Jump to content

How to add Tooltips to Context menu


Recommended Posts

Try this:

; right click on gui to bring up context Menu.
; right click on the "ok" button to bring up a controll specific context menu.

#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>

Global $MenuText, $MenuOpen, $MenuSave, $MenuInfo, $MenuAbout

Example()

Func Example()
  GUICreate("My GUI Context Menu", 300, 200)

  Local $contextmenu = GUICtrlCreateContextMenu()
  Local $newsubmenu = GUICtrlCreateMenu("new", $contextmenu)
  $MenuText = GUICtrlCreateMenuItem("text", $newsubmenu)
  $MenuOpen = GUICtrlCreateMenuItem("Open", $contextmenu)
  $MenuSave = GUICtrlCreateMenuItem("Save", $contextmenu)
  GUICtrlCreateMenuItem("", $contextmenu) ; separator
  $MenuInfo = GUICtrlCreateMenuItem("Info", $contextmenu)

  Local $button = GUICtrlCreateButton("OK", 100, 100, 70, 20)
  Local $buttoncontext = GUICtrlCreateContextMenu($button)
  $MenuAbout = GUICtrlCreateMenuItem("About button", $buttoncontext)

  GUIRegisterMsg( $WM_MENUSELECT, "WM_MENUSELECT" )

  GUISetState(@SW_SHOW)

  ; Run the GUI until the dialog is closed
  Local $iMsg = 0
  While 1
    $iMsg = GUIGetMsg()

    If $iMsg = $GUI_EVENT_CLOSE Then ExitLoop
    If $iMsg = $MenuText Then MsgBox($MB_SYSTEMMODAL, "Menu Selected", 'text')
    If $iMsg = $MenuOpen Then MsgBox($MB_SYSTEMMODAL, "Menu Selected", 'Open')
    If $iMsg = $MenuSave Then MsgBox($MB_SYSTEMMODAL, "Menu Selected", 'Save')
    If $iMsg = $MenuInfo Then MsgBox($MB_SYSTEMMODAL, "Menu Selected", 'Info')
    If $iMsg = $MenuAbout Then MsgBox($MB_SYSTEMMODAL, "Menu Selected", 'About')
  WEnd
  GUIDelete()
EndFunc   ;==>Example

Func WM_MENUSELECT( $hWnd, $iMsg, $iwParam, $ilParam )
  Local $idMenu = BitAND( $iwParam, 0xFFFF )
  Switch $idMenu
    Case $MenuText
      ToolTip( "Tooltip for text menu" )
    Case $MenuOpen
      ToolTip( "Tooltip for Open menu" )
    Case $MenuSave
      ToolTip( "Tooltip for Save menu" )
    Case $MenuInfo
      ToolTip( "Tooltip for Info menu" )
    Case $MenuAbout
      ToolTip( "Tooltip for About button" )
    Case Else
      ToolTip( "" )
  EndSwitch
EndFunc
Link to comment
Share on other sites

Thanks for your example. I noticed in the wm_menuselect function that it does not return any value does this mean that it will do the Autoit message handling or not?  Also does this function only work on context menus or other type of controls?

Thanks for your help.

Link to comment
Share on other sites

I am having one issue with this tool tip method. When one of the tooltips is up it seem to leave that tool tip visible if I do not mouse over one of the connext menu options that do not have a tooltip. So mouse over menu item with Tooltop. then just move my mouse away from the menus entirely and tool tip stays forever. Any suggestions?

Link to comment
Share on other sites

To remove a tooltip either the script must finish running or you will need to use a:

ToolTip("")

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

Why not use:
GUICtrlSetTip

Example of how i used it:

$VERSION = GUICtrlCreateLabel("Windows version:", 248, 16, 115, 17)
$VERSIONLIST = GUICtrlCreateCombo("", 248, 40, 201, 25, BitOR($CBS_DROPDOWNLIST, $WS_VSCROLL))
    GUICtrlSetTip($VERSIONLIST, "Choose your Windows version.")

If you hover your mouse over the combomenu then i shows a little thing with the text in it.

 

 

===================================================================

Update: Sorry posted this before i checked what your code did...don't know for sure if my example works for your situation...

Edited by Wingens
Link to comment
Share on other sites

  • 7 years later...

In 2022, the help file implies that GUICtrlSetTip works for any GUICtrlCreate...() function.  Is everyone certain that GUICtrlSetTip doesn't work for GUICtrlCreateMenuItem?  I know I can't get it to work ... I get a return value of 0.

#include <GUIConstantsEx.au3>

Example()

Func Example()
    GUICreate("My GUI control tip") ; will create a dialog box that when displayed is centered

    GUICtrlCreateLabel("my label", 10, 20)
    GUICtrlSetTip(-1, "tip of my label")

    $x = GUICtrlCreateMenu("&menu")
    GUICtrlSetTip(-1, "menu")

    GUICtrlCreateMenuItem("1",$x)
    GUICtrlSetTip(-1, "first option")

    GUISetState(@SW_SHOW)

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

        EndSwitch
    WEnd
EndFunc   ;==>Example

 

Edited by jaja714
adding code example
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...