PostMessage() sending a click to another window

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
Tvlao
Posts: 18
Joined: 29 Jun 2023, 03:39

PostMessage() sending a click to another window

11 May 2024, 16:05

For some reason this code doesn't work.
There are two windows. One window overlaps another. The top window with transparency intercepts clicks and directs them to the window below.

Code: Select all

OnMessage 0x0201, WM_LBUTTONDOWN

MakeLong(LoWord, HiWord ) 
{
	return (HiWord << 16) | (LoWord & 0xffff)
}

; --------------------------------------------

win1 := Gui("AlwaysOnTop")
win1.BackColor := 0xFFFFFF

Btn := win1.AddButton("Default x0 y0 w100", "Test")
Btn.OnEvent("Click", Btn_Click)  

Btn_Click(*){
    MsgBox "Btn_Click()"
}

win1.Show("x0 y0 w900 h400")

; --------------------------------------------
win2 := Gui("AlwaysOnTop")
win2.BackColor := 0xFFFFFF
win2.Show("x0 y0 w900 h400")
WinSetTransparent 100, "ahk_id" win2.Hwnd
; --------------------------------------------

WM_LBUTTONDOWN(wParam, lParam, msg, hwnd) {

    if(hwnd != win2.Hwnd){
        return
    }

    if wParam == 0x0001{
        ; LBUTTONDOWN
        PostMessage 0x201, 0x0001, MakeLong(4, 4),, win1.Hwnd
        ;WM_LBUTTONUP
        PostMessage 0x202, 0, MakeLong(4, 4), , win1.Hwnd              

    }
}
It is expected that the button in the window below will be pressed, but this does not happen.
PostMessage() doesn't seem to send messages.

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: Descolada, Draken, kczx3, mikeyww and 32 guests