Glam Prestige Journal

Bright entertainment trends with youth appeal.

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:

Link to Windows documentation of 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
}

1 Answer

SendMessage, Msg, wParam, lParam, Control, WinTitle

This is a send message command from AHK. See SendMessage Tutorial and SendMessage.

For a WM_NCHITTEST message, use 0x84 for Msg. See message list.

static WM_NCHITTEST := 0x84
SendMessage, WM_NCHITTEST, wParam, lParam, Control, WinTitle

Now the WM_NCHITTEST message require the cursor coordinate for lParam like this

lParam

The low-order word specifies the x-coordinate of the cursor. The coordinate is relative to the upper-left corner of the screen.

The high-order word specifies the y-coordinate of the cursor. The coordinate is relative to the upper-left corner of the screen.

Basically, x | (y << 16) is a way to squeeze 2 variables in one as required. See High-order word, low-order word and Bitwise operations in C.

Now, instead of using x and y as integer directly, we need to take care of the negative value. Use signed 16-bit values (Short) instead.

SendMessage, WM_NCHITTEST,, (x & 0xFFFF) | ((y & 0xFFFF) << 16),, ahk_id %w%
1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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