Sign in to follow this  
Followers 0

Just Want To Click On An Icon In The Systray

6 posts in this topic

Posted

This is killing me. I've spent days trying both with AutoIt as well as API calls in Visual Basic to just simply click on an icon in the systray. Nothing seems to work all the time.

I either need to double click on the icon to open up the program so I can then click the shutdown option. or I need to send a single click to the button while the form is minimized in the Systray.

At this point, I'll take either!

Anyone can point me in the general direction I'd appriciate it. I've run out of ideas.

Note: The icon in the systray is showing up as a Process and not an application however I've been able to use API calls and AutoIt to get the Process ID and then convert it to the windows Hwnd. But then all the ShowWindow, click window, pull my hair out window doesn't work.

Thanks

Share this post


Link to post
Share on other sites



Posted (edited)

I think this will help you to start (use Beta):

;==>Start

#include <guiconstants.au3>

#include <constants.au3>

;

Opt ("TrayAutoPause", 0)

Opt ("TrayMenuMode", 1)

Opt("GUICloseOnESC", 0)

opt("TrayAutoPause",0)

$appTitel="My Window"

;

;

$guiApp = GUICreate( $appTitel, 200, 200)

GUISetState()

$appState = @SW_SHOW

;

;

Do

$guiMsg = GUIGetMsg()

$trayMsg = TrayGetMsg()

if Not WinActive($appTitel) And $appState = @SW_SHOW Then ;lost focus minimize window

_ToggleAppState()

EndIf

Select

case $trayMsg = $TRAY_EVENT_PRIMARYDOWN

_ToggleAppState()

;Case other function from gui

EndSelect

;

until $guiMsg = $GUI_EVENT_CLOSE

;

; User defined function minimize and restore the gui

Func _ToggleAppState()

if $appState = @SW_HIDE then

$appState = @SW_SHOW

GUISetState(@SW_SHOW, $guiApp)

Else

$appState = @SW_HIDE

GUISetState(@SW_HIDE, $guiApp)

EndIf

EndFunc

Edited by Micha1405

Share this post


Link to post
Share on other sites

Posted

Look at this: SysTray_UDF

and you may also need Winspector if you want to send direct messages.

And in your example code is wrong idea that you could directly click on Control of hidden window.

If app is in systray this window may be destoyed (and not only hiden) and is created only after tray click.

Share this post


Link to post
Share on other sites

Posted

Possible workarounds:

  • ProcessClose(...)
  • Somtimes running the program again opens the window. For example, this method works with MSN Messenger to show its window so you can then use WinMenuSelectItem to sign off or close.

Share this post


Link to post
Share on other sites

Posted

Some programs only run as an icon in the System Tray. I have actually written some such programs.

Trying to find an arbitrary icon from the System Tray is most likely not a simple task. Good luck if you can figure something out. Direct Window messages might work.

Share this post


Link to post
Share on other sites

Posted

Thanks everyone. That information is def worth me keeping for future use. Luckily, I was able to make my code work. Turns out that the guy who wrote the systray program had 3 different hidden forms and I was trying to interact with the wrong form.

I found a program that uses Windows Enumeration to list all objects that currently exists along with their class info and such. Working my way down the tree I found the form that I needed and was able to (luckily) use the "TEXT" field to distinguish it from the other forms with the same class name.

Works great now. But the code and notes above sound like the way to go for the proper SysTray handling. This is just a down and dirty quick script for a couple of months until they get the programmer to make some changes.

Thanks again for your attention and time.

-B

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