Jump to content

TrayCreateItem setting ToolTips


 Share

Recommended Posts

I have tried _GUIToolTip_AddTool() & GUICtrlSetTip() & TrayItemGetHandle()  but have had no luck...is there a way that I have missed, or is it not possible to create a ToolTip for an individual item in the Tray?

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

I have tried this, with no success. It is only an example, so you with have to kill the process to kill the script.

 

#include <MsgBoxConstants.au3>
#include <TrayConstants.au3> ; Required for the $TRAY_ICONSTATE_SHOW constant.

Opt("TrayMenuMode", 3) ; The default tray menu items will not be shown and items are not checked when selected. These are options 1 and 2 for TrayMenuMode.


Global $tAlarmItem = TrayCreateItem("test")
;GUICtrlSetTip($tAlarmItem, "tip of my label")

Global $hAlarmItemTrayTip = TrayItemGetHandle($tAlarmItem)
GUICtrlSetTip($hAlarmItemTrayTip, "tip of my label")

While 1

WEnd

 

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

It's a good question.

Sorry I could not help.

Here's what I was trying for the record.

#include <MsgBoxConstants.au3>
#include <TrayConstants.au3> ; Required for the $TRAY_ICONSTATE_SHOW constant.
#include <GuiToolTip.au3>
HotKeySet("{Esc}", "_Exit")

Opt("TrayMenuMode", 7) ; The default tray menu items will not be shown and items are not checked when selected. These are options 1 and 2 for TrayMenuMode.
Opt("TrayIconHide", 0)
TraySetToolTip(" ")


$hwnd = WinGetHandle(AutoItWinGetTitle())
Global $tAlarmItem = TrayCreateItem("test")
$chwnd = ControlGetHandle($hwnd, "", $tAlarmItem) ;GUICtrlGetHandle($tAlarmItem)
$tt = _GUIToolTip_Create($chwnd)
_GUIToolTip_AddTool($tt, $chwnd, "Tip Text")

While 1
    Sleep(1000)
WEnd

Func _Exit()
    Exit
EndFunc   ;==>_Exit

 

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

GUICtrl functions generally work with control IDs and not handles to controls.Also, the TrayItemGetHandle function doesn't seem to work on TrayItems, only on TrayCreate IDs. Sounds like it's either misnamed, or not working as it should.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

It's a good question.

Sorry I could not help.

Here's what I was trying for the record.

#include <MsgBoxConstants.au3>
#include <TrayConstants.au3> ; Required for the $TRAY_ICONSTATE_SHOW constant.
#include <GuiToolTip.au3>
HotKeySet("{Esc}", "_Exit")

Opt("TrayMenuMode", 7) ; The default tray menu items will not be shown and items are not checked when selected. These are options 1 and 2 for TrayMenuMode.
Opt("TrayIconHide", 0)
TraySetToolTip(" ")


$hwnd = WinGetHandle(AutoItWinGetTitle())
Global $tAlarmItem = TrayCreateItem("test")
$chwnd = ControlGetHandle($hwnd, "", $tAlarmItem) ;GUICtrlGetHandle($tAlarmItem)
$tt = _GUIToolTip_Create($chwnd)
_GUIToolTip_AddTool($tt, $chwnd, "Tip Text")

While 1
    Sleep(1000)
WEnd

Func _Exit()
    Exit
EndFunc   ;==>_Exit

 

I have tried that as well, no luck, and that is what I actually tried first as my GUI already was using this same process/function with no issues

 

EDIT

I also tried the same code with the TrayItemGetHandle with no luck either

 

 

Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

A way to do it is to use a WH_MSGFILTER hook procedure to catch the messages from the tray menu:

#NoTrayIcon
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

Opt("TrayMenuMode", 3) ; The default tray menu items will not be shown and items are not checked when selected. These are options 1 and 2 for TrayMenuMode.

Global Const $tagMSG = "hwnd hwnd;uint message;wparam wParam;lparam lParam;dword time;int X;int Y"
Global $iDisplay, $iPrinter, $iAbout, $iExit

Example()

Func Example()
  Local $iSettings = TrayCreateMenu("Settings") ; Create a tray menu sub menu with two sub items.
  $iDisplay = TrayCreateItem("Display", $iSettings)
  $iPrinter = TrayCreateItem("Printer", $iSettings)
  TrayCreateItem("") ; Create a separator line.

  $iAbout = TrayCreateItem("About")
  TrayCreateItem("") ; Create a separator line.

  $iExit = TrayCreateItem("Exit")
  
  Local $hMessageHandler = DllCallbackRegister( "MessageHandler", "long", "int;wparam;lparam" )
  Local $hMessageHook = _WinAPI_SetWindowsHookEx( $WH_MSGFILTER, DllCallbackGetPtr( $hMessageHandler ), 0, _WinAPI_GetCurrentThreadId() )

  TraySetState(1) ; Show the tray menu.

  While 1
    Switch TrayGetMsg()
      Case $iAbout ; Display a message box about the AutoIt version and installation path of the AutoIt executable.
        MsgBox($MB_SYSTEMMODAL, "", "AutoIt tray menu example." & @CRLF & @CRLF & _
            "Version: " & @AutoItVersion & @CRLF & _
            "Install Path: " & StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", 0, -1) - 1)) ; Find the folder of a full path.

      Case $iDisplay, $iPrinter
        MsgBox($MB_SYSTEMMODAL, "", "A sub menu item was selected from the tray menu.")

      Case $iExit ; Exit the loop.
        ExitLoop
    EndSwitch
  WEnd

  DllCallbackFree( $hMessageHandler )
  _WinAPI_UnhookWindowsHookEx( $hMessageHook )
EndFunc   ;==>Example

Func MessageHandler( $nCode, $wParam, $lParam )
  Local $tMSG = DllStructCreate( $tagMSG, $lParam )
  Local $iMsg = DllStructGetData( $tMSG, "message" )
  If $iMsg = $WM_MENUSELECT Then
    Local $iwParam = DllStructGetData( $tMSG, "wParam" )
    Local $idMenu = BitAND( $iwParam, 0xFFFF )
    Switch $idMenu
      Case $iDisplay
        ToolTip( "Tooltip for Display menu" )
      Case $iPrinter
        ToolTip( "Tooltip for Printer menu" )
      Case $iAbout
        ToolTip( "Tooltip for About menu" )
      Case $iExit
        ToolTip( "Tooltip for Exit menu" )
      Case Else
        ToolTip( "" )
    EndSwitch
  EndIf
EndFunc

 

Link to comment
Share on other sites

A way to do it is to use a WH_MSGFILTER hook procedure to catch the messages from the tray menu:

#NoTrayIcon
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

Opt("TrayMenuMode", 3) ; The default tray menu items will not be shown and items are not checked when selected. These are options 1 and 2 for TrayMenuMode.

Global Const $tagMSG = "hwnd hwnd;uint message;wparam wParam;lparam lParam;dword time;int X;int Y"
Global $iDisplay, $iPrinter, $iAbout, $iExit

Example()

Func Example()
  Local $iSettings = TrayCreateMenu("Settings") ; Create a tray menu sub menu with two sub items.
  $iDisplay = TrayCreateItem("Display", $iSettings)
  $iPrinter = TrayCreateItem("Printer", $iSettings)
  TrayCreateItem("") ; Create a separator line.

  $iAbout = TrayCreateItem("About")
  TrayCreateItem("") ; Create a separator line.

  $iExit = TrayCreateItem("Exit")
  
  Local $hMessageHandler = DllCallbackRegister( "MessageHandler", "long", "int;wparam;lparam" )
  Local $hMessageHook = _WinAPI_SetWindowsHookEx( $WH_MSGFILTER, DllCallbackGetPtr( $hMessageHandler ), 0, _WinAPI_GetCurrentThreadId() )

  TraySetState(1) ; Show the tray menu.

  While 1
    Switch TrayGetMsg()
      Case $iAbout ; Display a message box about the AutoIt version and installation path of the AutoIt executable.
        MsgBox($MB_SYSTEMMODAL, "", "AutoIt tray menu example." & @CRLF & @CRLF & _
            "Version: " & @AutoItVersion & @CRLF & _
            "Install Path: " & StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", 0, -1) - 1)) ; Find the folder of a full path.

      Case $iDisplay, $iPrinter
        MsgBox($MB_SYSTEMMODAL, "", "A sub menu item was selected from the tray menu.")

      Case $iExit ; Exit the loop.
        ExitLoop
    EndSwitch
  WEnd

  DllCallbackFree( $hMessageHandler )
  _WinAPI_UnhookWindowsHookEx( $hMessageHook )
EndFunc   ;==>Example

Func MessageHandler( $nCode, $wParam, $lParam )
  Local $tMSG = DllStructCreate( $tagMSG, $lParam )
  Local $iMsg = DllStructGetData( $tMSG, "message" )
  If $iMsg = $WM_MENUSELECT Then
    Local $iwParam = DllStructGetData( $tMSG, "wParam" )
    Local $idMenu = BitAND( $iwParam, 0xFFFF )
    Switch $idMenu
      Case $iDisplay
        ToolTip( "Tooltip for Display menu" )
      Case $iPrinter
        ToolTip( "Tooltip for Printer menu" )
      Case $iAbout
        ToolTip( "Tooltip for About menu" )
      Case $iExit
        ToolTip( "Tooltip for Exit menu" )
      Case Else
        ToolTip( "" )
    EndSwitch
  EndIf
EndFunc

 

This is closer than I have got, so it will work, but a single question...I notice that the message comes up and is cut off, is there someway I can have it pop to from the left, rather than the right?

 

EDIT - it appears that depending on where you first interact with the control that it places it to the right, so going all the way to the right of the control, will cut off even more of the displayed tooltip.

Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

Yes, set the x and y parameters of ToolTip()

That is the ticket...thanks for everyone's help!!!

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

Link to comment
Share on other sites

And you can get the current mouse position as the X and Y members of the $tagMSG structure.

I have not worked with this type of variable before...I tried to use Msgbox to get the info, but that did not work, as I just got over lapping Msgboxes. How would I pull that info?
I have also tried:

ConsoleWrite(DllStructGetData($tagMSG, 'x') & @CRLF)
ConsoleWrite(DllStructGetData($tagMSG, 'y') & @CRLF)

I have also tried this:

 

Func MessageHandler($nCode, $wParam, $lParam)
    Local $tMSG = DllStructCreate($tagMSG, $lParam)
    Local $iMsg = DllStructGetData($tMSG, "message")

    Local $x, $y


Local $iMouse_X = DllStructCreate($tagMSG, $x)
Local $iMouse_Y = DllStructCreate($tagMSG, $y)
    ConsoleWrite(DllStructGetData($tagMSG, $iMouse_X) & ' x ' & @CRLF)
    ConsoleWrite(DllStructGetData($tagMSG, 'y') & @CRLF)

I would say I am a real noob when it comes to pointers, so any further help would be appreciative. For the time being, I am just using the desktop width as a way of getting it to a somewhat readable area - would use also stringlen() after creating the string for each tooltip

 

Actually a real noob at Structs - looking to use this as a way of maybe learning it a little better. Thanks again for your help.

Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

I got it now...took a bit, thanks again everyone

 

Func MessageHandler($nCode, $wParam, $lParam)
    Local $tMSG = DllStructCreate($tagMSG, $lParam)
    Local $iMsg = DllStructGetData($tMSG, "message")
    Local $iX = DllStructGetData($tMSG, "X")
    Local $iY = DllStructGetData($tMSG, "Y")

 

EDIT not resolved yet

Okay, that was giving me the mouse cords, but I was not able to get the tooltip to show...also I was getting (not every time, but at least once while hovering mouse over the toolbaritem - X = 1476462617 Y = -180939672

 

I do not think my screen is that large lol, so I must be doing something wrong?

Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

Yeah I get weird results with 

Case $iPrinter
        ToolTip( DllStructGetData($tMSG, "X") & "," & DllStructGetData($tMSG, "Y"))

I just used

Case $iDisplay
        ToolTip( "Tooltip for Display menu", MouseGetPos(0) - 150,  MouseGetPos(1) - 20)

 

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

It seems as if X and Y is only the current mouse position if it's a mouse related message eg. $WM_MOUSEMOVE. For other messages X and Y seems to be undefined. This should work:

#NoTrayIcon
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

Opt("TrayMenuMode", 3) ; The default tray menu items will not be shown and items are not checked when selected. These are options 1 and 2 for TrayMenuMode.

Global Const $tagMSG = "hwnd hwnd;uint message;wparam wParam;lparam lParam;dword time;int X;int Y"
Global $iDisplay, $iPrinter, $iAbout, $iExit

Example()

Func Example()
  Local $iSettings = TrayCreateMenu("Settings") ; Create a tray menu sub menu with two sub items.
  $iDisplay = TrayCreateItem("Display", $iSettings)
  $iPrinter = TrayCreateItem("Printer", $iSettings)
  TrayCreateItem("") ; Create a separator line.

  $iAbout = TrayCreateItem("About")
  TrayCreateItem("") ; Create a separator line.

  $iExit = TrayCreateItem("Exit")
  
  Local $hMessageHandler = DllCallbackRegister( "MessageHandler", "long", "int;wparam;lparam" )
  Local $hMessageHook = _WinAPI_SetWindowsHookEx( $WH_MSGFILTER, DllCallbackGetPtr( $hMessageHandler ), 0, _WinAPI_GetCurrentThreadId() )

  TraySetState(1) ; Show the tray menu.

  While 1
    Switch TrayGetMsg()
      Case $iAbout ; Display a message box about the AutoIt version and installation path of the AutoIt executable.
        MsgBox($MB_SYSTEMMODAL, "", "AutoIt tray menu example." & @CRLF & @CRLF & _
            "Version: " & @AutoItVersion & @CRLF & _
            "Install Path: " & StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", 0, -1) - 1)) ; Find the folder of a full path.

      Case $iDisplay, $iPrinter
        MsgBox($MB_SYSTEMMODAL, "", "A sub menu item was selected from the tray menu.")

      Case $iExit ; Exit the loop.
        ExitLoop
    EndSwitch
  WEnd

  DllCallbackFree( $hMessageHandler )
  _WinAPI_UnhookWindowsHookEx( $hMessageHook )
EndFunc   ;==>Example

Func MessageHandler( $nCode, $wParam, $lParam )
  Local Static $iMouseX, $iMouseY
  Local $tMSG = DllStructCreate( $tagMSG, $lParam )
  Local $iMsg = DllStructGetData( $tMSG, "message" )
  Switch $iMsg
    Case $WM_MENUSELECT
      Local $iwParam = DllStructGetData( $tMSG, "wParam" )
      Local $idMenu = BitAND( $iwParam, 0xFFFF )
      Switch $idMenu
        Case $iDisplay
          ToolTip( "Tooltip for Display menu", $iMouseX - 100, $iMouseY )
        Case $iPrinter
          ToolTip( "Tooltip for Printer menu", $iMouseX - 100, $iMouseY )
        Case $iAbout
          ToolTip( "Tooltip for About menu", $iMouseX - 100, $iMouseY )
        Case $iExit
          ToolTip( "Tooltip for Exit menu", $iMouseX - 100, $iMouseY )
        Case Else
          ToolTip( "" )
      EndSwitch
    Case $WM_MOUSEMOVE
      $iMouseX = DllStructGetData( $tMSG, "X" )
      $iMouseY = DllStructGetData( $tMSG, "Y" )
  EndSwitch
EndFunc

 

Link to comment
Share on other sites

That worked great...thanks - I had to add the stringlen() though, as each tool tip message was different in size, so some still extended outside of the display.

I thank you again for your help, but I wish it was as easy as adding tooltips to a GUI.

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

  • 1 year later...

Found a way by using _GUICtrlMenu_GetItemRect() on the menu item, then use 0 and 3 values for x and y of the tooltip.

To get coordinates of tray menu item, I used this:

$tMyTrayMenuItem = TrayCreateItem("My tray menu item")
$tMyTrayMenuItemPos = _GUICtrlMenu_GetItemCount(TrayItemGetHandle(0)) - 1
$rect = _GUICtrlMenu_GetItemRect(Default, TrayItemGetHandle(0), $tMyTrayMenuItemPos)
ToolTip("Tooltip text", $rect[0], $rect[3])

P.S.

The tricky part for me was get the menu item position to use in _GUICtrlMenu_GetItemRect(), because TrayCreateItem() returns control ID instead and I couldn't find any command that would reveal position of a menu item.

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

×
×
  • Create New...