autohotkeyui-automationsendmessagewin32guimicrosoft-documentation

AutoHotKey / SendMessage/ How should i retrieve the corresponding number of an action for a specific control with sendmessage


I'd like to select a date in my calendar with a AHK script. For this, i'm using the function sendMessage because i'd like to select a date from an external app. I'd like to use the SETCURSEL_MCM message from Microsoft documentation. How could i find the corresponding number from this message ? Bc it's not on this page https://learn.microsoft.com/en-us/windows/win32/controls/mcm-setcursel SendMessage, myCorrespondingNumberAsParam???, 0, lparam(which is my date),control, wintitle

By analogy, if i want to send a text to an edit control in notepad, i should send the WM_SETTEXT. The value of this message is clearly referenced by ahk doc as 12 for that control. But it's not the case for MCM_SETCURSEL message.

I tried to put the send message in a loop, an stop the loop when it executed the message, but it's too long, and it send bugs to the program.

If anyone could help me,

Thank you,

Gilles


Solution

  • You see from the documentation that this message is defined in the Commctrl.h header.
    So you want to open that header from your Windows SDK files, the path might be e.g.
    C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um, but really I recommend just using some proper Windows search engine (such as Everything), and searching that header name to find it quickly.

    Then you'll see in that header that the message is defined as follows:

    #define MCM_FIRST           0x1000
    
    // BOOL MonthCal_GetCurSel(HWND hmc, LPSYSTEMTIME pst)
    //   returns FALSE if MCS_MULTISELECT
    //   returns TRUE and sets *pst to the currently selected date otherwise
    #define MCM_GETCURSEL       (MCM_FIRST + 1)
    #define MonthCal_GetCurSel(hmc, pst)    (BOOL)SNDMSG(hmc, MCM_GETCURSEL, 0, (LPARAM)(pst))
    
    // BOOL MonthCal_SetCurSel(HWND hmc, LPSYSTEMTIME pst)
    //   returns FALSE if MCS_MULTISELECT
    //   returns TURE and sets the currently selected date to *pst otherwise
    #define MCM_SETCURSEL       (MCM_FIRST + 2)
    #define MonthCal_SetCurSel(hmc, pst)    (BOOL)SNDMSG(hmc, MCM_SETCURSEL, 0, (LPARAM)(pst))
    

    And there's your value, 0x1000 + 2.