Page 1 of 1
[SOLVED] SysTray Position
Posted: Tue Feb 01, 2011 3:55 am
by SkyManager
Does anybody know how to get the position of the SysTray Icon?
I want to display a window right above the SysTray Icon.
Re: SysTray Position
Posted: Tue Feb 01, 2011 12:33 pm
by IdeasVacuum
...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
Re: SysTray Position
Posted: Tue Feb 01, 2011 12:44 pm
by C64
IdeasVacuum wrote:subtract the typical height of the Task Bar
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.
Re: SysTray Position
Posted: Tue Feb 01, 2011 2:00 pm
by Trond
Even then it wouldn't solve the problem of knowing where in the systray the icon is.
Re: SysTray Position
Posted: Tue Feb 01, 2011 7:13 pm
by IdeasVacuum

I knew there had to be a catch. Is the Sys Tray effectively just another window? If so, what does that make the icons, are they 'buttons in disguise' or maybe a listicon gadget?
Re: SysTray Position
Posted: Tue Feb 01, 2011 7:25 pm
by idle
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)
Re: SysTray Position
Posted: Sun Feb 06, 2011 4:16 am
by SkyManager
Thanks for the tips
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
Posted: Sun Feb 06, 2011 2:40 pm
by Trond
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.
Your structure rcs does not bear much resemblance to a rectangle.
Re: SysTray Position
Posted: Tue Feb 08, 2011 6:55 am
by SkyManager
Thanks for the tips.
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
Posted: Tue Feb 08, 2011 11:01 am
by Shardik
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.
Why do you need to calculate the position of 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
I achieve the same result as with
Code: Select all
If Event = #PB_Event_SysTray
DisplayPopupMenu(menu, WindowID(gWind))
EndIf
And without the calculation of the icon position using WinAPI calls
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
Re: [SOLVED] SysTray Position
Posted: Fri Feb 18, 2011 4:04 am
by SkyManager
The answer is simple because I want to popup my own designed window with other gadgets, not just a plain popup menu.
Re: [SOLVED] SysTray Position
Posted: Fri Feb 18, 2011 10:21 am
by noorderling
But what if the taskbar is on the upper side , or left or right side?
Re: [SOLVED] SysTray Position
Posted: Sun Feb 20, 2011 6:20 am
by SkyManager
Oops! You're right
