Two functions sharing the same windows message Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
colt
Posts: 291
Joined: 04 Aug 2014, 23:12
Location: Portland Oregon

Two functions sharing the same windows message

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
}
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: Two functions sharing the same windows message  Topic is solved

09 Oct 2020, 12:26

Hi @colt,
colt wrote:
09 Oct 2020, 12:06
is it possible to programmatically detect the function name for a given windows message?
"OnMessage" wrote: This returns the name of the current legacy monitor for MsgNumber (blank if none):

Code: Select all

Name := OnMessage(MsgNumber)
source: OnMessage > Function Name vs Object > Function Name

hope this helps

A_AhkUser
my scripts

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot] and 181 guests