?
Solved

My Tray Icon doesnt work like i want

Posted on 2003-03-04
13
Medium Priority
?
270 Views
Last Modified: 2010-04-04
I want my app to be on top with focus when I double click the tray Icon. I have tried lots of example but all of them leave my app in the back and flash my app in the task bar.
Here is my code for now:

// Loading
  TrayIcon.cbSize := SizeOf(TrayIcon);
  TrayIcon.Wnd := Self.Handle;
  TrayIcon.uID := 0;
  TrayIcon.uFlags := NIF_ICON or NIF_TIP or NIF_MESSAGE;
  TrayIcon.uCallbackMessage := WM_MOUSEMOVE;
  TrayIcon.hIcon := Application.Icon.Handle;
  TrayIcon.szTip := MyAppTip;
  Application.OnMinimize := MinTray;

// Minimize
procedure TPrinc.MinTray(Sender: TObject);
begin
  Shell_notifyIcon(NIM_ADD, @TrayIcon);
  Princ.Visible:= False;
  Application.ShowMainForm := Visible;
end;

//Maximise
procedure TPrinc.MaxTray;
begin
  Princ.Show;
  Application.ShowMainForm := Visible;
  SetForegroundWindow(Application.Handle);
  Shell_notifyIcon(NIM_DELETE, @TrayIcon);
end;

//Double click on the tray
procedure TPrinc.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  if X = 515 then // Double click
    MaxTray;
end;

Sorry for my bad english :|
Thanks for helping me
0
Comment
Question by:ZaSz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 4
13 Comments
 
LVL 6

Accepted Solution

by:
MannSoft earned 150 total points
ID: 8065608
I know it sounds bad to plug my own software, but I wrote a tray component and Ive never noticed that problem.  You can get the source from http://www.mannsoft.ca/download.asp?file=ttray.zip if you want to take a look.
0
 
LVL 5

Expert Comment

by:Lukasz Lach
ID: 8066831
procedure TPrinc.MaxTray;
begin
 Princ.Show;
 Application.ShowMainForm := Visible;
 SetForegroundWindow(Application.Handle);
 Shell_notifyIcon(NIM_DELETE, @TrayIcon);
end;

stupid ;/
should be:

procedure TPrinc.MaxTray;
begin
 ShowWindow(Handle, SW_SHOW);
 SetForegroundWindow(Handle);
 Shell_notifyIcon(NIM_DELETE, @TrayIcon);
end;
0
 
LVL 1

Author Comment

by:ZaSz
ID: 8067699
anAKin, the form doesnt even show up with your code...
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Author Comment

by:ZaSz
ID: 8067752
Thanks MannSoft
0
 
LVL 5

Expert Comment

by:Lukasz Lach
ID: 8070030
depends in wchih state your form ism you can also try
Application.Restore -> if minimized,
Show -> the same
but the point is SetForegroundWindow(Handle); which i always use when form isn't minimized, only under other applications... that works and it's no need to use component for tray...
0
 
LVL 1

Author Comment

by:ZaSz
ID: 8071029
I had the SetForeGroundWindow, but it was only flashing the taskbar :(
0
 
LVL 5

Expert Comment

by:Lukasz Lach
ID: 8073214
procedure TForm1.FormCreate(Sender: TObject);
var
  LockTimeOut: Integer;
begin
  LockTimeOut := 0;
  SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, Pointer(LockTimeOut), SPIF_UPDATEINIFILE or SPIF_SENDCHANGE);
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var
  LockTimeOut: Integer;
begin
  LockTimeOut := 40000;
  SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, Pointer(LockTimeOut), SPIF_UPDATEINIFILE or SPIF_SENDCHANGE);
end;

and simply use Application.BringToFront; in your MaxTray procedure ;-) I said there is no need to use component... The thing is that Tray components are just useless...
0
 
LVL 6

Expert Comment

by:MannSoft
ID: 8076163
I think them being useless is a matter of personal opinion.  I have many programs that are loaded the entire time my computer is running.  Some are not interactive and it is wasteful to be in the system tray, but it is better than the taskbar where it would take even more space.

And some programs, like winamp for example, are interactive.  When it is minimized to the system tray not only does it take up less space than it would on the taskbar, but i can right click and control it from the popup menu without restoring the form.

So I think tray components definitely have their place.
0
 
LVL 1

Author Comment

by:ZaSz
ID: 8076208
And an other thing with component: It's easy to use!
0
 
LVL 5

Expert Comment

by:Lukasz Lach
ID: 8078146
I didn't say that placing icon in the tray is useless, i said it about using a component for that...

ZaSz:
So let's mabye use components for everyting:
TIntToStr, TStrToInt, TFormat, TInc and TDec, because it would be easier... Using component when there is realy no need to do that (cause you had it API like, the olny thing was that app was blinbing, bot showing) is needless...
0
 
LVL 6

Expert Comment

by:MannSoft
ID: 8080158
I think that isnt a very good example.  How does using a component for simple functions make it easier?

A tray component certainly makes things easier.  Maybe not if you only write one application.  But what if you write 10 that use the system tray?  That means you need to rewrite the same code 10 times which really increases the possibility for error.  Either that or you copy and paste 10 times.  That's much easier, but what if you find you've made an error somewhere, or want to implement some new feature.  Now you have to go back and change the same code in 10 different places.  With a component you dont have to worry about that.  Fix the component once, recompile the applications that use it, and voila you are done.

To me it's all a matter of efficiency.  If one way is going to obviously save me time and effort and the other way only has disadvantages, it really isnt a hard decision to make...  But I guess everyone is entitled to their opinion.
0
 
LVL 5

Expert Comment

by:Lukasz Lach
ID: 8080305
Sure, you are right...
But are we supposed to use someone's component every time we have a litte problem while solvig the solution? That is not the best way to learn how to code, is it?
0
 
LVL 6

Expert Comment

by:MannSoft
ID: 8081591
No of course simply using the component isnt the best way to learn how to code.  But I think thats why most component developers usually release the source code.  They realize other people might be interested in seeing how it works, and to me, seeing strange function calls and having to look them up to see what they do is a great way to learn.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month14 days, 9 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question