I am currently popping up a popup near the SysTray icons when Application.OnActivate occurs. however I need to popup it now where the App button was clicked on TaskBar (next to start menu). How to find out the exact location of my app's taskbar icon that was just clicked?
I know I could simply allow the App Form appear and ask user to click a button that makes a popup to appear, but I need more simpler/faster to use GUI for my App.
if (mode = 2) or ( (x =0) and (y=0) ) then begin
ABData.cbSize := SizeOf(TAppBarData);
//ABData.hWnd := FindWindow('Shell_TrayWnd', nil);
SHAppBarMessage(ABM_GETTASKBARPOS, ABData);
with ABData.Rc do begin
if (Top > 0) then Edge := ABE_BOTTOM
else if (Bottom < Screen.Height) then Edge := ABE_TOP
else if Right < Screen.Width then Edge := ABE_LEFT
else Edge := ABE_RIGHT;
end;
X := 1; Y := 1;
if Edge = ABE_BOTTOM then begin
X := ABData.Rc.Right-20;
Y := ABData.Rc.Top;
end else if Edge = ABE_TOP then begin
X := ABData.Rc.Right;
Y := ABData.Rc.Top;
end else if Edge = ABE_LEFT then begin
X := ABData.Rc.Left;
Y := ABData.Rc.Bottom;
end else if Edge = ABE_RIGHT then begin
X := ABData.Rc.Right;
Y := ABData.Rc.Bottom;
end;
end;
CodePudding user response:
It seems the easiest solution was to check mouse position and pop where mouse was:
pt := Mouse.CursorPos;
x := pt.x;
y:= pt.y;
PS: there seems to be also another solution in C# and C :
How to find TaskBar button screen Rect of a window?
CodePudding user response:
If by "taskbar icon" you mean a system tray icon that you own, then you can use Shell_NotifyIconGetRect()
. But, if you mean a Taskbar button instead, then there is no (official) way to determine its location on the Taskbar.