Thank you, TheArkive.
Well, then I'll probably stick with global OnMessage and do it like this. I think it's a usable approach.
Code: Select all
G := Gui()
button := G.Add("Button", "vbutton", "Drag me somewhere")
OnMessage 0x0201, WM_LBUTTONDOWN, -1 ;
WM_LBUTTONDOWN(wParam, lParam, msg, hwnd)
{
X := lParam & 0xFFFF
Y := lParam >> 16
thisGuiControl := GuiCtrlFromHwnd(hwnd)
if thisGuiControl {
if thisGuiControl.Name = "button"
startDrag(X, Y, thisGuiControl)
}
}
startDrag(X, Y, GuiControl) {
; ControlGetPos &cX, &cY, &cWidth, &cHeight, GuiControl
; if (X < cX) or (X > (cX + cWidth)) or (Y < cY) or (Y > (cY + cHeight)) {
; return ; in case I click outside the control but it's still triggered
; }
tooltip "startDrag Function"
KeyWait "LButton"
MouseGetPos ,, &OutputVarWin
tooltip "I am over " WinGetTitle("ahk_id " OutputVarWin)
sleep 1000
tooltip
; do stuff based on the window and guiControl
}
G.Show()
Are you trying to do a "real drag and drop" ?
Not sure what you mean. Probably not, I just want a mouse gesture to trigger a function.
PS. I'd like to understand all the stuff with callbacks, messages, events you've mentioned. But it'll definitely take some time and effort (trying other people's code, reading documentation and forum posts)
I've been using a lot GuiControl.OnEvent, I've read the tutorial
https://lexikos.github.io/v2/docs/misc/SendMessage.htm and already used program spyxx to detect windows messages.
And for example I also use a lot "copy all to clipboard" from putty with: (I found the numbers in the source code and it magically works)
SendMessage 0x0112, 0x0170, , , "ahk_pid " putty_pid
But that's basically it. If anyone knows about a good windows messaging&events tutorial for noobs, please let me know