Hi all.
After beating my head into an even more ugly state, I couldnt find any way
of getting a handle on the TrayIcon - the problem is its created not as a
window, rather as an Icon. You can get the handle then location of the
system tray OK, but where each Icon is situated is much less obvious. Here
is my code below for getting the system tray icons centre. It is crappy, but
may be of use to some of you who need to do more than just bring up menus.
The downside is that the TrayIcon must be 'wiped' before the right and left
positions are useable.
In my use of this we can go to Previous or Next track on our MPEG player by
clicking to the right or left of the icon, once the icon is 'wiped'. Until
it is, there is a singular function of Pause/Play:
procedure TPlayerForm.RxTrayMouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
begin
//The following code requires a user to 'wipe' the icon, before a centre ref
is available
//TrayIconCentre, TrayIconLeft,TrayIconRight are global
if (TrayIconCentre > 0) then
begin
//check in case new tray incons installed or removed (new position)
if (X > TrayIconRight+10) or (X < TrayIconLeft-10) then
begin
TrayIconCentre := 0;
TrayIconRight := 0;
TrayIconLeft := 2000;
end
else exit; //All is well, use TrayIconCentre as the ref point
end;
if X > TrayIconRight then
TrayIconRight := X
else if (X < TrayIconLeft) and (TrayIconRight - X <= 16)
then TrayIconLeft := X;
if TrayIconRight - TrayIconLeft > 14 then
TrayIconCentre := round((TrayIconLeft + TrayIconRight) / 2);
end;
//Example code of using the TrayIconCentre
procedure TPlayerForm.RxTrayClick(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
//Allow short delay just in case double click (form made visible)
delay(GetDoubleClickTime());
if Playerform.Visible then exit;
if CurrentState = 'PAUSED' then
begin XAudioPlayer.Play; exit; end;
if TrayIconCentre = 0 then //Not 'wiped' so Pause/Play only available
begin
menuPauseClick(self);
exit;
end
else
if (x > TrayIconCentre) and (X - TrayIconCentre > 3)
then menunextclick(self) //Next track
else if (x < TrayIconCentre) and (TrayIconCentre - X > 3)
then menupreviousclick(self) //Previous track
else menupauseclick(self);
end;
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz