Jump to content
Sign in to follow this  
MacScript

How to add Tooltips to Context menu

Recommended Posts

MacScript

HI all, been looking around but have not had much luck and finding out how to add tooltips to some of my context menu options. If some one could point me in the correct direction I would appreciate it.

Thanks

Share this post


Link to post
Share on other sites
LarsJ

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

Share this post


Link to post
Share on other sites
MacScript

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.

Share this post


Link to post
Share on other sites
MacScript

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?

Share this post


Link to post
Share on other sites
MikahS

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

 

Share this post


Link to post
Share on other sites
Wingens

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

Share this post


Link to post
Share on other sites
MacScript

Because you can not do that command for context menus. That command is for other type of controls.

Share this post


Link to post
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
Sign in to follow this  

×