Show Menu tips with modeless menu

Post your working scripts, libraries and tools
User avatar
SKAN
Posts: 363
Joined: 29 Sep 2013, 16:58

Show Menu tips with modeless menu

11 Dec 2013, 21:12

Code: Select all

/*
  DISCLAIMER : Experimental code 
  Show Menu tips with modeless menu / SKAN ( [email protected] ) / 12-Dec-2013  
  Topic:  http://ahkscript.org/boards/viewtopic.php?t=971
 
  Info:
  WM_MENUSELECT() creates/updates the following global variables:
  OMH_Handle   :  Handle/hMenu of the active menu.
  OMH_Flags    :  Flags to be used for testing whether the item is disabled/checked etc.
  OMH_IsPopup  :  Will be true when a submenu is being highlighted or false otherwise.
  OMH_String   :  The Menu Item string. Will contain a TAB if item uses accelerator key.
  OMH_ItemRef  :  Depends on OMH_IsPopup. It is MenuItemPos when OMH_IsPopup is 1 (true) 
                                             or CommandID   when OMH_IsPopup is 0 (false). 

  Reference:

  majkinetor & Mr.Chris
  http://goo.gl/P8mQhG  How to add menu tooltip or right mouse button notification
  http://goo.gl/Bc35dV  Dropped messages
                                             
------------------------------------------------------------------------------------------      
*/  


If IsLabel( "OnMenuHilite" ) 
  OnMessage( 0x11F, "WM_MENUSELECT" ), OnMessage( 0x211, "WM_ENTERMENULOOP" )
  

WM_ENTERMENULOOP() {
  Return True
}

WM_MENUSELECT( wParam, lParam, Msg, hWnd ) {
Global OMH_Handle, OMH_Flags, OMH_IsPopup, OMH_ItemRef, OMH_String
  VarSetCapacity( OMH_String ) < 2048 ? VarSetCapacity( OMH_String, 2048 ) : 0
    
  OMH_Handle  := lParam                       ; hMenu 
  OMH_Flags   := wParam >> 16                 ; wParam HiWord,  Refer MSDN: goo.gl/Xs9QwU
  OMH_IsPopup := ( OMH_Flags & 0x10 = 0x10 )  ; Test 'Flags' for MF_POPUP=0x10 
  OMH_ItemRef := ( wParam & 0xFFFF )          ; Extract MenuItemPos/CommandID from LoWord       

  DllCall( "GetMenuString", UInt,OMH_Handle   ; MF_BYPOSITION = 0x400, MF_BYCOMMAND = 0 
            , UInt,OMH_ItemRef, Str,OMH_String, UInt,1024, UInt,OMH_IsPopup ? 0x400 : 0 )

  If IsLabel( Label := "OnMenuHilite" )
   SetTimer, %Label%, -1
}
Oversimplified example:
  • Image

Code: Select all

; http://ahkscript.org/boards/viewtopic.php?t=971

; Copy/Paste code or #Include OnMenuHilite.ahk 

#SingleInstance, Force
Menu, Tray, MainWindow
Menu, MyMenuBar, Add, &File, :Tray
Gui, Menu, MyMenuBar
Gui, Add, StatusBar
Gui, Show, w480 h360, DEMO - Show Menu tips with modeless menu  
Return

#IfWinActive DEMO - Show Menu tips with modeless menu
 F10::OnMessage( 0x211 ) ? OnMessage( 0x211, "" ) : OnMessage( 0x211, "WM_ENTERMENULOOP" )
#IfWinActive

OnMenuHilite:
 SB_SetText( MenuItemTip( OMH_ItemRef ) ) 
Return
     

MenuItemTip( MenuID ) {
 IfEqual, MenuID, 65300, Return, "Show Script Window ( ahk_id " A_ScriptHwnd " )"
 IfEqual, MenuID, 65301, Return, "Run : " RegExReplace( A_AhkPath, ".exe", ".chm" )
 IfEqual, MenuID, 65302, Return, "Run Window Info tool : " 
                               . RegExReplace( A_AhkPath, "AutoHotkey.exe","AU3_Spy.exe" )
 IfEqual, MenuID, 65303, Return, "Close and launch again : " A_ScriptFullpath
 IfEqual, MenuID, 65304, Return, "Edit this script in default editor : " A_ScriptFullpath
 IfEqual, MenuID, 65305, Return, "Suspending hotkeys will change TrayIcon to 'S'"
 IfEqual, MenuID, 65306, Return, "Pausing the script will turn TrayIcon to RED-H"
 IfEqual, MenuID, 65307, Return, "Exit this application"
}
User avatar
Chef
Posts: 50
Joined: 14 Nov 2013, 13:01

Re: Show Menu tips with modeless menu

12 Dec 2013, 12:31

Hello SKAN,
This seems to work with all menuBar items and subItems, can it also work with non-menuBar menus?
User avatar
SKAN
Posts: 363
Joined: 29 Sep 2013, 16:58

Re: Show Menu tips with modeless menu

12 Dec 2013, 12:44

Chef wrote:can it also work with non-menuBar menus?
Yes! Even with system menu ( right click on titlebar ).
However, it doesn't work with Traymenu attached to Trayicon, but can be worked around.
User avatar
Chef
Posts: 50
Joined: 14 Nov 2013, 13:01

Re: Show Menu tips with modeless menu

12 Dec 2013, 12:55

How come its not working here then Image

Code: Select all

#SingleInstance, Force

If IsLabel( "OnMenuHilite" ) 
	OnMessage( 0x11F, "WM_MENUSELECT" ), OnMessage( 0x211, "WM_ENTERMENULOOP" )
  
Menu, Tray, MainWindow
menu, view, add, Big, view
menu, view, add, Small, view

Menu, MyMenuBar, Add, &File, :Tray
Menu, MyMenuBar, Add, &view, :view
Gui, Menu, MyMenuBar
Gui, Add, button, w150 h30 gView,View menu
Gui, Add, StatusBar
Gui, Show, w480 h360, DEMO - Show Menu tips with modeless menu  
Return

view:
	menu, view, show
	return

#IfWinActive DEMO - Show Menu tips with modeless menu
	F10::OnMessage( 0x211 ) ? OnMessage( 0x211, "" ) : OnMessage( 0x211, "WM_ENTERMENULOOP" )
#IfWinActive

OnMenuHilite:
	SB_SetText( MenuItemTip( OMH_ItemRef ) ) 
	Return
	
WM_ENTERMENULOOP() {
	Return True
}
     
WM_MENUSELECT( wParam, lParam, Msg, hWnd ) {
	Global OMH_Handle, OMH_Flags, OMH_IsPopup, OMH_ItemRef, OMH_String
	VarSetCapacity( OMH_String ) < 2048 ? VarSetCapacity( OMH_String, 2048 ) : 0

	OMH_Handle  := lParam                       ; hMenu 
	OMH_Flags   := wParam >> 16                 ; wParam HiWord,  Refer MSDN: goo.gl/Xs9QwU
	OMH_IsPopup := ( OMH_Flags & 0x10 = 0x10 )  ; Test 'Flags' for MF_POPUP=0x10 
	OMH_ItemRef := ( wParam & 0xFFFF )          ; Extract MenuItemPos/CommandID from LoWord       

	DllCall( "GetMenuString", UInt,OMH_Handle   ; MF_BYPOSITION = 0x400, MF_BYCOMMAND = 0 
			, UInt,OMH_ItemRef, Str,OMH_String, UInt,1024, UInt,OMH_IsPopup ? 0x400 : 0 )

	If IsLabel( Label := "OnMenuHilite" )
		SetTimer, %Label%, -1
}

MenuItemTip( MenuID ) {
	return MenuID
}
User avatar
SKAN
Posts: 363
Joined: 29 Sep 2013, 16:58

Re: Show Menu tips with modeless menu

12 Dec 2013, 15:07

Chef wrote:How come its not working here then Image
Ah! I see. I should have tested properly before posting :(.
Menu, Show halts the thread and the alternate is to call TrackPopupMenu().
Please allow me sometime, and I will post a wrapper for TrackPopupMenu().
User avatar
SKAN
Posts: 363
Joined: 29 Sep 2013, 16:58

Re: Show Menu tips with modeless menu

13 Dec 2013, 07:01

Menu_Show() is an alternate to Menu, Show, which can display menu without blocking monitored messages...

Code: Select all

Menu_Show( hMenu, hWnd=0, mX="", mY="", Flags=0x1 ) {
 ; http://ahkscript.org/boards/viewtopic.php?p=7088#p7088
 ; Flags: TPM_RECURSE := 0x1, TPM_RETURNCMD := 0x100, TPM_NONOTIFY := 0x80
 VarSetCapacity( POINT, 8, 0 ), DllCall( "GetCursorPos", UInt,&Point ) 
 mX := ( mX <> "" ) ? mX : NumGet( Point,0 )
 mY := ( mY <> "" ) ? mY : NumGet( Point,4 )
Return DllCall( "TrackPopupMenu", UInt,hMenu, UInt,Flags ; TrackPopupMenu()  goo.gl/CosNig
               , Int,mX, Int,mY, UInt,0, UInt,hWnd ? hWnd : WinActive("A"), UInt,0 )
}
..but the catch is: To get handle ( hMenu ) for a Menuname, it has to be attached to a MenuBar.
There already is a function from lexikos, which does this: MI_GetMenuHandle(), and can be used as follows:

Code: Select all

hViewmenu := MI_GetMenuHandle( "view" ) ; Get it from: http://www.autohotkey.net/~Lexikos/lib/MI.ahk
...
...
GuiContextMenu:
 Menu_Show( hViewMenu )
Return
User avatar
joedf
Posts: 7075
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada
Contact:

Re: Show Menu tips with modeless menu

13 Dec 2013, 11:34

interesting! ;)
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500 @ 3.00 GHz, 16GB DDR4 2133 MHz, NVIDIA GTX 1060 6GB | [About Me] | [ASPDM - StdLib Distribution]
[Populate the AHK MiniCity!] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library] | [About the AHK Foundation]

Return to “Scripts and Functions”

Who is online

Users browsing this forum: Bing [Bot], freespacing, Ovg, robodesign and 38 guests