Page 1 of 1

How to get screen coords of my Icon in System Tray?

Posted: Mon Sep 09, 2013 12:25 pm
by roleg
I create some Icon in the System Tray.
How can I get its X and Y?

It is necessary to draw over the Icon a pop-up image.

Re: How to get screen coords of my Icon in System Tray?

Posted: Mon Sep 09, 2013 1:17 pm
by IdeasVacuum
That is going to be difficult I think. The systray is in fact a small excutable and the tray icons are added to a toolbar. When another icon is added, your icon could change position.

However, since the tooltip 'knows' where the icon is, perhaps the tooltip could be replaced with an image?

Re: How to get screen coords of my Icon in System Tray?

Posted: Mon Sep 09, 2013 1:25 pm
by roleg
yes, I can replace image with another outer layer, this is not a problem.

problem: I cannot find Icon position on the screen...

Code: Select all

OpenWindow(0, 100, 150, 300, 100, "Test", #PB_Window_Normal)
DataSection
  FileIconLabel:
  IncludeBinary "file_server.ico"
EndDataSection
IconID = CatchImage(FileIcon, ?FileIconLabel)
AddSysTrayIcon(1, WindowID(0), IconID)
I need to find position (X,Y) that Tray Icon ID(1)

Re: How to get screen coords of my Icon in System Tray?

Posted: Mon Sep 09, 2013 1:40 pm
by IdeasVacuum

Re: How to get screen coords of my Icon in System Tray?

Posted: Mon Sep 09, 2013 9:41 pm
by Bisonte
The simpliest way is to draw your popup info to the right bottom of desktop 0.
All other programs do it also (e.g. Avira, Firewall, and so on).

If you want to react of a mouse click .... Hey you have the "MouseClick" ... DesktopMouseX() DesktopMouseY()... ;)

Re: How to get screen coords of my Icon in System Tray?

Posted: Mon Sep 09, 2013 10:34 pm
by jassing
Bisonte wrote:The simpliest way is to draw your popup info to the right bottom of desktop 0.
All other programs do it also (e.g. Avira, Firewall, and so on).

If you want to react of a mouse click .... Hey you have the "MouseClick" ... DesktopMouseX() DesktopMouseY()... ;)
a small peeve of mine, but an important note: the start-bar/menu bar, system-tray, whatever, can be moved to the left, right or top of the screen. programs that just do "lower right" show a little less care for the user than most. I've found most programs do pay attention to the location of the bar.

Re: How to get screen coords of my Icon in System Tray?

Posted: Mon Sep 09, 2013 11:34 pm
by IdeasVacuum
You can work out where the taskbar is and it's size by verifying the screen work area, which excludes the task bar. So, something like this:

Code: Select all

rSysTray.RECT
SystemParametersInfo_(#SPI_GETWORKAREA, 0, @rSysTray, 0)
Debug rSysTray\top
Debug rSysTray\left
Debug rSysTray\bottom
Debug rSysTray\right

Re: How to get screen coords of my Icon in System Tray?

Posted: Tue Sep 10, 2013 6:52 am
by Danilo
IdeasVacuum wrote:You can work out where the taskbar is and it's size by verifying the screen work area, which excludes the task bar. So, something like this:

Code: Select all

rSysTray.RECT
SystemParametersInfo_(#SPI_GETWORKAREA, 0, @rSysTray, 0)
Debug rSysTray\top
Debug rSysTray\left
Debug rSysTray\bottom
Debug rSysTray\right
Does not work if the user has more Toolbars/AppBars. I always have a toolbar on the right side of my desktop
with menus for all the programs I use. On Windows, Linux, and Mac. On Windows you don't know what is the AppBar and
what is the TaskBar by looking at the work area.

You can get the TaskBar co-ordinates and edge:

Code: Select all

Procedure.s TaskbarEdgeToString(edge)
    Select edge
        Case #ABE_BOTTOM : ProcedureReturn "bottom"
        Case #ABE_LEFT   : ProcedureReturn "left"
        Case #ABE_RIGHT  : ProcedureReturn "right"
        Case #ABE_TOP    : ProcedureReturn "top"
    EndSelect
EndProcedure

SHAppBarMessage_(#ABM_GETTASKBARPOS,@appBarData.APPBARDATA)
Debug appBarData\rc\left
Debug appBarData\rc\top
Debug appBarData\rc\right  - appBarData\rc\left
Debug appBarData\rc\bottom - appBarData\rc\top
Debug TaskbarEdgeToString(appBarData\uEdge)

Debug FindWindow_("Shell_TrayWnd",0)
So you know now where the TaskBar is (top,bottom,left,right), and you know it's dimension.
Together with the WorkArea, you are able to get the correct top,bottom,left,right WorkArea corner
for displaying a popup info window, if that's enough.

For getting the Tray window, you could enumerate the child windows of the TaskBar etc.
Search engines show many results how to do that: "tray icon position"

The function Shell_NotifyIconGetRect_() requires Windows7 or newer, if that's OK. ;)

Re: How to get screen coords of my Icon in System Tray?

Posted: Tue Sep 10, 2013 4:42 pm
by IdeasVacuum
FindWindow_("Shell_TrayWnd",0) does not work on XP (at least, not on my PC), and of course there could be more than one....

It does seem like an almost impossible task to get this right for all possible scenarios, so I think a compromise needs to be considered.

Re: How to get screen coords of my Icon in System Tray?

Posted: Mon Oct 07, 2013 8:40 pm
by IdeasVacuum
Take a look at this code by Sparkie: http://www.purebasic.fr/english/viewtopic.php?p=236653

Re: How to get screen coords of my Icon in System Tray?

Posted: Mon Oct 07, 2013 9:44 pm
by netmaestro
The problem with 5-year-old code on this subject is that programming the notification area changed significantly from WinXP -> Vista/7/8. If you're going to code for it you need two paths and check the windows version for which path you're going to take.