0

I am relatively new to the world of programming. I've been using AutoHotkey a lot and came accross a code using WM_NCHITTEST. The code below: When the mouse cursor is above a window Title Bar, Right Click minimizes the window and Middle Click closes it. When the X coordinate of the mouse cursor is > 0, everything works fine (all windows and monitors to the RIGHT of the Main Display). When X < 0, nothing works (everything to the LEFT of the Main Display). Is someone able to explain this?

Specifically, the "WM_NCHITTEST,, x | (y << 16)", I don't quite understand.

Link to the Original Code: https://www.autohotkey.com/boards/viewtopic.php?f=76&t=63022&p=269207&hilit=titlebar+middle+click#p269207

Link to Windows documentation of WM_NCHITTEST: https://docs.microsoft.com/en-us/windows/win32/inputdev/wm-nchittest

#If MouseIsOverTitlebar()
RButton::SendMessage 0x112, 0xF020
MButton::WinClose

MouseIsOverTitlebar() {
    static WM_NCHITTEST := 0x84, HTCAPTION := 2
    CoordMode Mouse, Screen
    MouseGetPos x, y, w
    if WinExist("ahk_class Shell_TrayWnd ahk_id " w)  ; Exclude taskbar.
        return false
    SendMessage WM_NCHITTEST,, x | (y << 16),, ahk_id %w%
    WinExist("ahk_id " w)  ; Set Last Found Window for convenience.
    return ErrorLevel = HTCAPTION
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.