Code: Select all
OnMessage(0x201, "WM_LBUTTONDOWN")
Test1 := new TestClass("Test1", 300, 400)
return
class TestClass {
__New(Name, x, y) {
Gui, New, +Hwndhwnd
Gui %hwnd%: -Caption +AlwaysOnTop +ToolWindow +OwnDialogs
Gui %hwnd%: Add, Text, x5 y5 w100 h20, % Name
Gui %hwnd%: Add, Text, x5 y30 w100 h20 hwndhPos, % x ", " y
Gui %hwnd%: Show, % "x" x " y" y " w110 h55 NA"
this.hPos := hPos, this.hwnd := hwnd, this.Name := Name
}
}
WM_LBUTTONDOWN() {
global Test1
PostMessage, 0xA1, 2
KeyWait, LButton
WinGetPos, x,y,,, % "ahk_id " Test1.hwnd
GuiControl, % Test1.hwnd ":", % Test1.hPos, % x ", " y
}
Code: Select all
Test1 := new TestClass("Test1", 300, 400)
;Test2 := new TestClass("Test2", 450, 400)
return
class TestClass {
__New(Name, x, y) {
Gui, New, +Hwndhwnd
Gui %hwnd%: -Caption +AlwaysOnTop +ToolWindow +OwnDialogs
Gui %hwnd%: Add, Text, x5 y5 w100 h20, % Name
Gui %hwnd%: Add, Text, x5 y30 w100 h20 hwndhPos, % x ", " y
Gui %hwnd%: Show, % "x" x " y" y " w110 h55 NA"
this.hPos := hPos, this.hwnd := hwnd, this.Name := Name
OnMessage(0x201, this["WM_LBUTTONDOWN"]) ; my intention: I want to monitor WM_LBUTTONDOWN message by WM_LBUTTONDOWN method
}
WM_LBUTTONDOWN() {
ToolTip % "LButton down on " this.Name ; I would like to see: "LButton down on Test1" but I see just "LButton down on "
PostMessage, 0xA1, 2
KeyWait, LButton
ToolTip
WinGetPos, x,y,,, % "ahk_id " this.hwnd ; doesn't work. "this" obviously doesn't refer to derived object?
GuiControl, % this.hwnd ":", % this.hPos, % x ", " y ; doesn't work. "this" obviously doesn't refer to derived object?
}
}
I also tried to use WM_LBUTTONDOWN(wParam, lParam, msg, hwnd) as a method instead of just WM_LBUTTONDOWN() (no params) but I can't register it via OnMessage() because it has 5 params; 4 + one hidden; "this"... and the limit for OnMessage is 4. My plan was to compare 4. parameter; hwnd with A_Gui and if they match, do stuff... - or is this nonsense - they will always match in WM_LBUTTONDOWN case?if (A_Gui = hwnd of any window which belongs to object derived from TestClass)
--> do stuff...
else
--> this is a window which doesn't belong to object derived from TestClass - do nothing, don't interfere
Thanks in advance.