Two functions sharing the same windows message
Posted: 09 Oct 2020, 12:06
I have two functions in the same script that rely on reacting to the same windows message Receive_WM_COPYDATA. One function is in a include file and the other is in the main script. For simplicty my example uses the WM_LBUTTONDOWN message. The script functions how I want, but it relies on a global variable to restore the functionality. How can this be improved? Also is it possible to find the linked function name for any windows message? Thanks!
Code: Select all
Gui, Add, Text,, Click anywhere in this window.
Gui, Add, Edit, w200 vMyEdit
Gui, Show
OnMessage(0x201, "WM_LBUTTONDOWN")
global functionRestoreName
return
WM_LBUTTONDOWN(wParam, lParam)
{
X := lParam & 0xFFFF
Y := lParam >> 16
if A_GuiControl
Ctrl := "`n(in control " . A_GuiControl . ")"
ToolTip You left-clicked in Gui window #%A_Gui% at client coordinates %X%x%Y%.%Ctrl%
}
GuiClose:
ExitApp
f8::
myLibraryFunction()
return
;these two functions will be in include file
;the original function name "WM_LBUTTONDOWN" will be unknown
myLibraryFunction() ;temporarily hijack windows message
{
;is it possible to programmatically detect the function name for a given windows message?
;functionRestoreName := msgFunction(0x201) ; something like this
functionRestoreName := "WM_LBUTTONDOWN"
OnMessage(0x201, "anotherLibraryFunction")
}
anotherLibraryFunction() ;once message is received set back to default behavior as specified by main script
{
tooltip temporary functionality %functionRestoreName%
OnMessage(0x201, functionRestoreName) ;restore default functionality
}