[SOLVED] SysTray Position
-
- Enthusiast
- Posts: 339
- Joined: Tue Jan 30, 2007 5:47 am
- Location: Hong Kong
[SOLVED] SysTray Position
Does anybody know how to get the position of the SysTray Icon?
I want to display a window right above the SysTray Icon.
I want to display a window right above the SysTray Icon.
Last edited by SkyManager on Tue Feb 08, 2011 7:08 am, edited 1 time in total.
-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: SysTray Position
...should be simple? Verify the screen size, subtract the typical height of the Task Bar:
Code: Select all
ExamineDesktops()
#MainScreen = 0
#MyWindow = 1
iScreenWidth.l = DesktopWidth(#MainScreen)
iScreenHeight.l = DesktopHeight(#MainScreen)
iTaskBarHeight.l = 60
iMyWindowWidth.l = 250
iMyWindowHeight.l = 150
iWinPosX.l = iScreenWidth - iMyWindowWidth
iWinPosY.l = iScreenHeight - (iMyWindowHeight + iTaskBarHeight)
If OpenWindow(#MyWindow,iWinPosX,iWinPosY,iMyWindowWidth,iMyWindowHeight,"Window above Sys Tray",#PB_Window_SystemMenu)
EndIf
Repeat
iEvent.i = WaitWindowEvent()
Until iEvent = #PB_Event_CloseWindow
End
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: SysTray Position
No way! The height of the Taskbar is different on every PC. Even from XP to 7. It depends what theme Windows is running (Classic or XP/Aero), and if the user has set it larger than usual (to show the date with the clock on XP), whether it's locked or not, the system font size, and so on. And not everyone has it at the bottom. You simply cannot hard-code a value of 60 and assume it's going to be alright. There's code in these forums that show how to get the exact value, even taking into account if it's not at the bottom.IdeasVacuum wrote:subtract the typical height of the Task Bar
Re: SysTray Position
Even then it wouldn't solve the problem of knowing where in the systray the icon is.
-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: SysTray Position

IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: SysTray Position
Code: Select all
SystemParametersInfo_(#SPI_GETWORKAREA,0,@rc,0)
GetCursorPos_(@pt)
offset = GetSystemMetrics_(#SM_CYMENU) ;if it's a pop up menu
DisplayPopupMenu(#menu,WindowID(gWind),pt\x-30,rc\bottom-offset)
Windows 11, Manjaro, Raspberry Pi OS


-
- Enthusiast
- Posts: 339
- Joined: Tue Jan 30, 2007 5:47 am
- Location: Hong Kong
Re: SysTray Position
Thanks for the tips
But it seems to me that there is an error in defining the rc structure.
Any help for me?
But it seems to me that there is an error in defining the rc structure.
Any help for me?
Code: Select all
Structure pts
x.l
y.l
EndStructure
pt.pts
Structure rcs
bottom_offset.l
EndStructure
rc.rcs
gWind = 0
menu = 1
If Not CreatePopupMenu(menu) : End : EndIf
MenuItem(1,"TEST-1")
MenuItem(2,"TEST-2")
MenuItem(3,"TEST-3")
SystemParametersInfo_(#SPI_GETWORKAREA, 0, @rc, 0)
GetCursorPos_(@pt)
offset = GetSystemMetrics_(#SM_CYMENU) ;if it's a pop up menu
If Not OpenWindow(gWind, 100, 150, 300, 100, "Test", #PB_Window_Normal) : End : EndIf
runOnceOnly.l = #True
Repeat
If (runOnceOnly)
runOnceOnly = #False
DisplayPopupMenu(menu, WindowID(gWind), pt\x-30, rc\bottom_offset)
EndIf
Event = WaitWindowEvent()
Until (Event = #PB_Event_CloseWindow)
Re: SysTray Position
Your structure rcs does not bear much resemblance to a rectangle.MSDN wrote:SPI_GETWORKAREA
Retrieves the size of the working area. The working area is the portion of the screen not obscured by the tray. The pvParam parameter must point to the RECT structure that receives the coordinates of the working area.
-
- Enthusiast
- Posts: 339
- Joined: Tue Jan 30, 2007 5:47 am
- Location: Hong Kong
Re: SysTray Position
Thanks for the tips.
My test is working now
My test is working now

Code: Select all
Structure pts
x.l
y.l
EndStructure
pt.pts
rc.RECT
gWind = 0
menu = 1
SystemTray = 2
FileIcon = 3
If Not OpenWindow(gWind, 100, 150, 300, 100, "Test", #PB_Window_Normal) : End : EndIf
DataSection
FileIconLabel:
IncludeBinary "traymenu.bmp"
EndDataSection
IconID = CatchImage(FileIcon, ?FileIconLabel)
AddSysTrayIcon(SystemTray, WindowID(gWind), IconID)
SysTrayIconToolTip(SystemTray, "Title")
If Not CreatePopupMenu(menu) : End : EndIf
MenuItem(1,"TEST-1")
MenuItem(2,"TEST-2")
MenuItem(3,"TEST-3")
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_SysTray
SystemParametersInfo_(#SPI_GETWORKAREA, SystemTray, @rc, 0)
GetCursorPos_(@pt)
offset = GetSystemMetrics_(SystemTray) ;if it's a pop up menu
DisplayPopupMenu(menu, WindowID(gWind), pt\x, rc\bottom-offset + 30)
EndIf
Until (Event = #PB_Event_CloseWindow)
FreeImage(FileIcon)
FreeMenu(menu)
FreeMenu(SystemTray)
Re: [SOLVED] SysTray Position
Why do you need to calculate the position of the SysTray icon?SkyManager wrote:Does anybody know how to get the position of the SysTray Icon?
I want to display a window right above the SysTray Icon.
Because PureBasic does that for you automatically if you omit the
x and y coordinates. So in Windows XP SP3 and Windows 7 with
Code: Select all
If Event = #PB_Event_SysTray
SystemParametersInfo_(#SPI_GETWORKAREA, SystemTray, @rc, 0)
GetCursorPos_(@pt)
offset = GetSystemMetrics_(SystemTray) ;if it's a pop up menu
DisplayPopupMenu(menu, WindowID(gWind), pt\x, rc\bottom-offset + 30)
EndIf
Code: Select all
If Event = #PB_Event_SysTray
DisplayPopupMenu(menu, WindowID(gWind))
EndIf
and structures it should even work crossplatform. This example works
in Windows and Linux (Suse Linux Enterprise Server 10 SP3 x64):
Code: Select all
If Not OpenWindow(gWind, 100, 150, 300, 100, "Test") : End : EndIf
IconID = LoadImage(FileIcon, #PB_Compiler_Home + "examples/sources/Data/Drive.bmp")
If IconID
AddSysTrayIcon(SystemTray, WindowID(gWind), IconID)
SysTrayIconToolTip(SystemTray, "Title")
If Not CreatePopupMenu(menu) : End : EndIf
MenuItem(1,"TEST-1")
MenuItem(2,"TEST-2")
MenuItem(3,"TEST-3")
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_SysTray
DisplayPopupMenu(menu, WindowID(gWind))
EndIf
Until (Event = #PB_Event_CloseWindow)
EndIf
-
- Enthusiast
- Posts: 339
- Joined: Tue Jan 30, 2007 5:47 am
- Location: Hong Kong
Re: [SOLVED] SysTray Position
The answer is simple because I want to popup my own designed window with other gadgets, not just a plain popup menu.
-
- User
- Posts: 16
- Joined: Fri Jul 16, 2010 3:54 pm
Re: [SOLVED] SysTray Position
But what if the taskbar is on the upper side , or left or right side?
-
- Enthusiast
- Posts: 339
- Joined: Tue Jan 30, 2007 5:47 am
- Location: Hong Kong
Re: [SOLVED] SysTray Position
Oops! You're right 
