Question

I am trying to make a hotkey that will copy a file in Windows Explorer, flip to my open new draft email and attach it. I am going to assume that there will be zero or one new draft email windows open. If there are more than one, I'll just take one and hope it's the right one. This is an interactive process. My trouble is in writing an IfWinExist that can tell the difference between an open sent email window and an open new draft email window. How can I tell the difference? I'm using Outlook 2010 and AutoHotkey v1.1.12.00

Thanks for your help!

Was it helpful?

Solution

Here's a commented code example:

SetTitleMatchMode, 2

/* Choose the window title acoording to your language:
*  English: Message
*  German:  Nachricht
*  ...
*/
msgWin := "- Message ahk_exe outlook.exe"
WinGet, hwndList, List, %msgWin%
Loop % hwndList
{
    aHwnd := hwndList%A_Index%
    WinGetTitle, ttl, % "ahk_id " aHwnd
    ControlGetText, btnText, Button1, ahk_id %aHwnd%
    /* If you want to be sure, check for the text of the send button: 
    *  English: &Send, German: &Senden, ...
    */
    if(!btnText || !InStr(btnText, "Send")) {
        MsgBox, Not a draft window:`n%ttl%
    } else {
        MsgBox, Draft window:`n%ttl%
    }
}

It basically checks for each open Message window, if there's a Send button in it (for me, it's Button1). If there's no such button, it's not a draft.
As described in the code's comments, you'll have to adjust the language dependent identifiers. You may also have to change the control name (Button1), window spy will give you that info.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top