Sign in to follow this  
Followers 0
Reveller

Right and left click on system tray icon

4 posts in this topic

#1 ·  Posted (edited)

I am writing my first ever AutoIt program ;) What I want is:

  • icon in system tray
  • right-click on icon displays "about, help, exit" menu
  • clicking on a menu item opens a Msgbox
  • left-click on icon gives all available information of the active window (title, errorcode if there is one, etc) in a Msgbox

I have figured out how to put an icon in the systemtray and have created a little menu. But my questions are:

  • How do I see whether the click on the icon is a leftclick of rightclick?
  • I found out how to the the active windows' title, but what other information is available of the active window?

Any help would be greatly appreciated!

Opt("TrayMenuMode",1)   ; Hide default tray menu items

$aboutitem = TrayCreateItem("About")
$infoitem  = TrayCreateItem("Info")
$exititem  = TrayCreateItem("Exit")

TraySetIcon("Shell32.dll",-87)
TraySetState()

While 1
  $msg = TrayGetMsg()
  Select
    Case $msg = 0
      ContinueLoop
    Case $msg = $aboutitem
      Msgbox(64, "About", "Dennis' Cool Q&A app!")
  Case $msg = $infoitem
      MsgBox(64, "POPUP", "HELLO WORLD!")
    Case $msg = $exititem
      ExitLoop
  EndSelect
WEnd

Exit
Edited by Reveller

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Try

#include <Constants.au3>
Opt("TrayMenuMode",1)   ; Hide default tray menu items

TraySetIcon("Shell32.dll",-87)
TraySetState()

While 1
  $msg = TrayGetMsg()
  Select
    Case $msg = 0
      ContinueLoop
    Case $msg = $TRAY_EVENT_PRIMARYDOWN
    Msgbox(64, "", "left click!")
    Case $msg = $TRAY_EVENT_SECONDARYDOWN
    Msgbox(64, "", "right click!")      
  EndSelect
WEnd

Exit

and for window information see for "winget" in helpfile search...

Edited by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

To still have the option of a menu you need to disable the standard response of the trayicon. (Standard response is opening the menu on a left, or a right click, you only want it to respond to right click). The function to do so is TraySetClick(8).

Then you need to set a seperate response to left clicking as wakillon demonstrated, otherwise left clicking does nothing.

What information you want to get from a window is a bit unclear to me. How is this information usually accessible to the user? What kind of window should this work on?

This should get the clicking working the way you want it:

#include <Constants.au3>

Opt("TrayMenuMode",1) ; Hide default tray menu items
TraySetIcon("Shell32.dll",-87)
TraySetClick(8) ;only show the menu when right clicking
$aboutitem = TrayCreateItem("About")
$infoitem = TrayCreateItem("Info")
$exititem = TrayCreateItem("Exit")

While 1
 Switch TrayGetMsg() ;switch seems nicer in this case
 Case 0
     ContinueLoop
    Case $TRAY_EVENT_PRIMARYDOWN ;reaction to left clicking
     Msgbox(64,"","left click!")
 Case $aboutitem
     TrayItemSetState($aboutitem,$TRAY_UNCHECKED) ;stop the automated (un)checking when clicked
     Msgbox(64, "About", "Dennis' Cool Q&A app!")
 Case $infoitem
     TrayItemSetState($infoitem,$TRAY_UNCHECKED) ;stop the automated (un)checking when clicked
     MsgBox(64, "POPUP", "HELLO WORLD!")
 Case $exititem
     ExitLoop
 EndSwitch
WEnd
Exit

Share this post


Link to post
Share on other sites

Wow! Thanks, the both of you. Tvern, I left the annoying (un)checking for later, but you already solved this as well. I will now dove into the documentation to find out how I can get all available information from the active window ;)

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  
Followers 0