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

Just starting out? Need help? Post your questions and find answers here.
roleg
User
User
Posts: 51
Joined: Wed Feb 24, 2010 2:07 pm

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

Post 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.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

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

Post 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?
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
roleg
User
User
Posts: 51
Joined: Wed Feb 24, 2010 2:07 pm

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

Post 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)
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

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

Post by IdeasVacuum »

IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Bisonte
Addict
Addict
Posts: 1305
Joined: Tue Oct 09, 2007 2:15 am

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

Post 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()... ;)
PureBasic 6.21 (Windows x64) | Windows 11 Pro | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom​​
English is not my native language... (I often use DeepL.)
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

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

Post 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.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

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

Post 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
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

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

Post 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. ;)
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

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

Post 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.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

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

Post by IdeasVacuum »

Take a look at this code by Sparkie: http://www.purebasic.fr/english/viewtopic.php?p=236653
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

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

Post 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.
BERESHEIT
Post Reply