Saad Posted September 5, 2022 Share Posted September 5, 2022 I'm writing an application where I'd like to add a tooltip to a GUI Menu control. In the below code, I'd like to display $sBookmarkTT when I hover over $idBookmark1 "Bookmark1". #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 625, 442, 370, 232) $idFile = GUICtrlCreateMenu("&File") $idFileExit = GUICtrlCreateMenuItem("&Exit", $idFile) $idBookmarks = GUICtrlCreateMenu("&Bookmarks") $idBookmark1 = GUICtrlCreateMenuItem("Bookmark1", $idBookmarks) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### $sBookmarkTT = "This is a tooltip for bookmark1" While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Thanks. Link to comment Share on other sites More sharing options...
Nine Posted September 6, 2022 Share Posted September 6, 2022 Recently I solved a very similar issue with menu. See the code I made and you can easily adjust it for tooltip. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Solution Danyfirex Posted September 6, 2022 Solution Share Posted September 6, 2022 (edited) You can do this: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiMenu.au3> #include <GuiToolTip.au3> #Region ### START Koda GUI section ### Form= Global $Form1 = GUICreate("Form1", 625, 442, 370, 232) Global $idFile = GUICtrlCreateMenu("&File") Global $idFileExit = GUICtrlCreateMenuItem("&Exit", $idFile) Global $idBookmarks = GUICtrlCreateMenu("&Bookmarks") Global $idBookmark1 = GUICtrlCreateMenuItem("Bookmark1", $idBookmarks) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_MENUSELECT, "WM_MENUSELECT") #EndRegion ### END Koda GUI section ### Global $g_sBookmarkTT = "This is a tooltip for bookmark1" Global $g_hMain = _GUICtrlMenu_GetMenu($Form1) Global $g_hBookmark1 = _GUICtrlMenu_GetItemSubMenu($g_hMain, 1) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func WM_MENUSELECT($hWnd, $iMsg, $wParam, $lParam) Local $iIndex = BitAND($wParam, 0xFFFF) Local $iFlag = BitShift($wParam, 16) If BitAND($iFlag, $MF_MOUSESELECT) Then ToolTip("") If $lParam = $g_hBookmark1 Then ToolTip($g_sBookmarkTT, Default, Default, "", 0, 1) EndIf EndIf Return $GUI_RUNDEFMSG EndFunc ;==>WM_MENUSELECT Saludos Edited September 6, 2022 by Danyfirex Zedna, mikell and pixelsearch 3 Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
pixelsearch Posted September 6, 2022 Share Posted September 6, 2022 @Danyfirex very nice, with WM_MENUSELECT and MF_MOUSESELECT, I never used them until now I have 2 questions concerning your script. Please look at the 1st minor display issue : This happens for example when you click on the Bookmarks menu, then hover over the Bookmark1 item (the tooltip appears), then press Escape (or left key for example) and the tooltip doesn't disappear at once (as it should). I'm aware OP didn't mention the keyboard to navigate but well, if we can prevent bad displays, let's do it A 2nd issue will appear as soon as there are more than 1 item in the Bookmarks menu (which is a frequent case) for example by adding this line to your script : Global $idBookmark2 = GUICtrlCreateMenuItem("Bookmark2", $idBookmarks) To solve both issues, I tried this : * Replacing MF_MOUSESELECT with MF_HILITE, it seems to solve issue #1 * Using $iIndex to display the Tooltip only for the Bookmark1 item, it seems to solve issue #2 expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiMenu.au3> #include <GuiToolTip.au3> #Region ### START Koda GUI section ### Form= Global $Form1 = GUICreate("Form1", 625, 442, 370, 232) Global $idFile = GUICtrlCreateMenu("&File") Global $idFileExit = GUICtrlCreateMenuItem("&Exit", $idFile) Global $idBookmarks = GUICtrlCreateMenu("&Bookmarks") Global $idBookmark1 = GUICtrlCreateMenuItem("Bookmark1", $idBookmarks) Global $idBookmark2 = GUICtrlCreateMenuItem("Bookmark2", $idBookmarks) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_MENUSELECT, "WM_MENUSELECT") #EndRegion ### END Koda GUI section ### Global $g_sBookmarkTT = "This is a tooltip for bookmark1" Global $g_hMain = _GUICtrlMenu_GetMenu($Form1) Global $g_hBookmark1 = _GUICtrlMenu_GetItemSubMenu($g_hMain, 1) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func WM_MENUSELECT($hWnd, $iMsg, $wParam, $lParam) Local $iIndex = BitAND($wParam, 0xFFFF) ConsoleWrite($iIndex & @crlf) Local $iFlag = BitShift($wParam, 16) ; If BitAND($iFlag, $MF_MOUSESELECT) Then If BitAND($iFlag, $MF_HILITE) Then ToolTip("") ; If $lParam = $g_hBookmark1 Then If $lParam = $g_hBookmark1 And $iIndex = 6 Then ToolTip($g_sBookmarkTT, Default, Default, "", 0, 1) EndIf EndIf Return $GUI_RUNDEFMSG EndFunc ;==>WM_MENUSELECT The problem is I added a ConsoleWrite in the script to know that the Bookmark1 item has an index of 6. Maybe there's another simple way to know if the highlited item is Bookmark1 (the one associated with the Tooltip) without using a constant 6 in the script ? Link to comment Share on other sites More sharing options...
Danyfirex Posted September 6, 2022 Share Posted September 6, 2022 I just did it fast, never mind about other things like keyboard etc. thank you for your solution. 😉 Saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
kurtykurtyboy Posted September 7, 2022 Share Posted September 7, 2022 (edited) @pixelsearch I think you will find that your constant 6 is also the ID returned by GUICtrlCreateMenuItem. So, it should be as simple as: $iIndex = $idBookmark1 expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiMenu.au3> #include <GuiToolTip.au3> #Region ### START Koda GUI section ### Form= Global $Form1 = GUICreate("Form1", 625, 442, 370, 232) Global $idFile = GUICtrlCreateMenu("&File") Global $idFileExit = GUICtrlCreateMenuItem("&Exit", $idFile) Global $idBookmarks = GUICtrlCreateMenu("&Bookmarks") Global $idBookmark1 = GUICtrlCreateMenuItem("Bookmark1", $idBookmarks) Global $idBookmark2 = GUICtrlCreateMenuItem("Bookmark2", $idBookmarks) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_MENUSELECT, "WM_MENUSELECT") #EndRegion ### END Koda GUI section ### Global $g_sBookmarkTT = "This is a tooltip for bookmark1" Global $g_hMain = _GUICtrlMenu_GetMenu($Form1) Global $g_hBookmark1 = _GUICtrlMenu_GetItemSubMenu($g_hMain, 1) ConsoleWrite($idBookmark1 & @CRLF) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func WM_MENUSELECT($hWnd, $iMsg, $wParam, $lParam) Local $iIndex = BitAND($wParam, 0xFFFF) ConsoleWrite($iIndex & @crlf) Local $iFlag = BitShift($wParam, 16) ; If BitAND($iFlag, $MF_MOUSESELECT) Then If BitAND($iFlag, $MF_HILITE) Then ToolTip("") ; If $lParam = $g_hBookmark1 Then If $lParam = $g_hBookmark1 And $iIndex = $idBookmark1 Then ToolTip($g_sBookmarkTT, Default, Default, "", 0, 1) EndIf EndIf Return $GUI_RUNDEFMSG EndFunc ;==>WM_MENUSELECT Edited September 7, 2022 by kurtykurtyboy pixelsearch 1 Link to comment Share on other sites More sharing options...
pixelsearch Posted September 7, 2022 Share Posted September 7, 2022 @kurtykurtyboy you're right, I should have spent a bit more time on this. IIRC, controls id's always start from 3, for example if we add this line : ConsoleWrite($idFile & " " & $idFileExit & " " & $idBookmarks & " " & $idBookmark1 & " " & $idBookmark2 & @CRLF) Console display : 3 4 5 6 7 Now always the same question : where are controls id's 1 & 2 in AutoIt ? I remember having found by accident a possible control id = 1 corresponding to : GUICtrlCreateTabItem("") Then I asked LarsJ if it was correct. His answer was : I didn't know that controlID #1 is used by GUICtrlCreateTabItem(""). I also don't know what controlID #2 is used for. If we work on the help file example of GUICtrlCreateTabItem, we can display in the Console this controlID = 1 expandcollapse popup#include <GUIConstantsEx.au3> Example() Func Example() GUICreate("My GUI Tab", 250, 150); will create a dialog box that when displayed is centered GUISetBkColor(0x00E0FFFF) GUISetFont(9, 300) Local $idTab = GUICtrlCreateTab(10, 10, 200, 100) ; GUICtrlCreateTabItem("tab0") Local $idTabItem = GUICtrlCreateTabItem("tab0") GUICtrlCreateLabel("label0", 30, 80, 50, 20) GUICtrlCreateButton("OK0", 20, 50, 50, 20) GUICtrlCreateInput("default", 80, 50, 70, 20) GUICtrlCreateTabItem("tab----1") GUICtrlCreateLabel("label1", 30, 80, 50, 20) GUICtrlCreateCombo("", 20, 50, 60, 120) GUICtrlSetData(-1, "Trids|CyberSlug|Larry|Jon|Tylo|guinness", "Jon"); default Jon GUICtrlCreateButton("OK1", 80, 50, 50, 20) GUICtrlCreateTabItem("tab2") GUICtrlSetState(-1, $GUI_SHOW); will be display first GUICtrlCreateLabel("label2", 30, 80, 50, 20) GUICtrlCreateButton("OK2", 140, 50, 50) ; GUICtrlCreateTabItem(""); end tabitem definition Local $idTabItemEND = GUICtrlCreateTabItem(""); end tabitem definition ConsoleWrite($idTab & " " & $idTabItem & " " & $idTabItemEND & @crlf) GUICtrlCreateLabel("Click on tab and see the title", 20, 130, 250, 20) GUISetState(@SW_SHOW) Local $idMsg ; Loop until the user exits. While 1 $idMsg = GUIGetMsg() If $idMsg = $GUI_EVENT_CLOSE Then ExitLoop If $idMsg = $idTab Then ; display the clicked tab WinSetTitle("My GUI Tab", "", "My GUI Tab" & GUICtrlRead($idTab)) EndIf WEnd EndFunc ;==>Example Console : 3 4 1 If this is correct, maybe we should ask Jon one of these days what is controlID #2 in AutoIt ? Link to comment Share on other sites More sharing options...
Saad Posted September 7, 2022 Author Share Posted September 7, 2022 @Danyfirex Nice, thank you. All, thank you so much for your input. Link to comment Share on other sites More sharing options...
Danyfirex Posted September 7, 2022 Share Posted September 7, 2022 @pixelsearch Quote Now always the same question : where are controls id's 1 & 2 in AutoIt ? id 1: is a hidden edit control AutoIt creates over an overlapped hidden window named "AutoIt v3" id 2: It seems to be when we do GUICreate it increments the id count so when we create our first control we get it assigned with id 3. Saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
Administrators Jon Posted September 14, 2022 Administrators Share Posted September 14, 2022 From the source: // Limits #define AUT_GUI_FIRSTCONTROL 3 // First usable control ID (1 (IDOK) and 2 (IDCANCEL) is used by the OS and 0 is not used) #define AUT_GUI_MAXCONTROLID 65535 // Maximum control ID - limited to WORD size (unsigned short) Obviously caused a clash in an early build. Lots of 1 and 2 used by the OS so we just picked the first free one. pixelsearch 1 Deployment Blog: https://www.autoitconsulting.com/site/blog/ SCCM SDK Programming: https://www.autoitconsulting.com/site/sccm-sdk/ Link to comment Share on other sites More sharing options...
pixelsearch Posted September 14, 2022 Share Posted September 14, 2022 @Jon damn... you're quick. Thanks a lot for your answer Link to comment Share on other sites More sharing options...
Administrators Jon Posted September 14, 2022 Administrators Share Posted September 14, 2022 From winuser.h /* * Dialog Box Command IDs */ #define IDOK 1 #define IDCANCEL 2 #define IDABORT 3 #define IDRETRY 4 #define IDIGNORE 5 #define IDYES 6 #define IDNO 7 #if(WINVER >= 0x0400) #define IDCLOSE 8 #define IDHELP 9 #endif /* WINVER >= 0x0400 */ Windows button controls for OK and Cancel are usually 1 and 2 and IIRC mapped to Enter (Default) and Esc (Cancel) - the rest of them don't come into play in a custom dialog. We could have just picked 100 to be honest and made it all the more cryptic TheDcoder 1 Deployment Blog: https://www.autoitconsulting.com/site/blog/ SCCM SDK Programming: https://www.autoitconsulting.com/site/sccm-sdk/ Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now