Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

[Solved]Custom GUI "special labels" using OnMessag


  • Please log in to reply
2 replies to this topic
Mystiq
  • Members
  • 83 posts
  • Last active: Nov 06 2011 07:07 PM
  • Joined: 08 Jan 2007
What i'm trying to archive:
Basically i'm trying to add custom subroutine(s) for other window events using the way AHK standard "special labels" works. I'm talking about the GUI label option you can set e.g. "Gui 2:+LabelMyGui ".

How i'm trying to do it:
Using OnMessage to catch submenu/menubar activation event(s) (WM_INITMENUPOPUP / WM_INITMENU ) and manually update menu content (disable/enable items etc.) before the menu is displayed.
In sort i would use this OnMessage method and using the returned hwnd to find out the label and GoSub to it's custom "special label".

WM_INITMENUPOPUP(wParam, lParam, msg, hwnd)
{
	...
	CustomSpecialLabel := ThisLabel . "InitMenu"
	If (IsLabel(CustomSpecialLabel))
		GoSub %CustomSpecialLabel%		; E.g. MyGuiInitMenu.
Return
}

The problem:
Essentially the problem is how to get the label you have set on specific window using the provided hwnd.

Solution/Workaround:

As suggested below, storing the label using the window hwnd works for problem #1. However after some extensive research on the forums for the problem #2, e.g. capturing these other messages, i managed to find solution for it as well.

Problem best described by Chris in "Dropped messages" thread. Same thread also contains example by majkinetor how to monitor these other messages.

When the GUI window procedure receives WM_ENTERMENULOOP from any menu (even one the script displays via DllCall), the script is marked uninterruptible. Consequently, messages below 0x312 like WM_MENUSELECT are not monitored (as mentioned in the docs).


Adding the following code allows these "unmonitored" messages to be processed. After brief testing using "WM_MENUSELECT" and "WM_INITMENU" it seems to work.

OnMessage(0x211, "WM_ENTERMENULOOP")

...

WM_ENTERMENULOOP(){
Return 100
}

Update:


Alternatively if one don't use the custom label names at all and instead the normal way, e.g. "1GuiSize", you can do this without storing the label in global variable by simply using the provided A_Gui as it is provided information in the OnMessage function.

WM_INITMENUPOPUP(wParam, lParam, msg, hwnd)
{
	...
	CustomSpecialLabel := A_Gui . "InitMenu"
	If (IsLabel(CustomSpecialLabel))
		GoSub %CustomSpecialLabel%		; E.g. 1GuiInitMenu.
Return
}

As for limitations, apart from obvious, is that you can't use these labels inside functions, which you can do with real "special labels". However this method provides a way to link new "event/message" to a specific GUI.

P.S. Renamed the thread to be more specific.

Thanks again!

VxE
  • Moderators
  • 3622 posts
  • Last active: Dec 24 2015 02:21 AM
  • Joined: 07 Oct 2006
I think you'd have to keep track of the label and HWND in a separate variable, something like:
Gui, 2:+LastFound
hwnd := WinExist()
Gui, 2:+LabelMySpecialLabel
Label%hwnd% = MySpecialLabel
then the variable Label74493857 will contain the right label. (the number will be different, o'course)

Mystiq
  • Members
  • 83 posts
  • Last active: Nov 06 2011 07:07 PM
  • Joined: 08 Jan 2007
Thats actually how i'm thinking of doing it, unless theres more direct way of finding out the label. Anyways, thanks for posting. :)

Edit1:

I'm not actually able to get the OnMessage part to work, not sure why. Theres rather old post about already without any solution.

<!-- m -->http://www.autohotke...pic.php?t=12092<!-- m -->

Anyone got ideas about this?

Update:
Verified with Winspector, "AutohotkeyGui" does receive but OnMessage does not seem to act on those messages.