Solved

Repair missing tray icon.

Posted on 2006-07-07
11
491 Views
Last Modified: 2010-04-05
Hi.

My application stays minimized in the system tray.
Sometimes explorer crash and when it reloads it always forget to create the icons of my application.

How can i add a check to see if my icons is missing ?

Thanks in advance.
0
Comment
Question by:CodedK
11 Comments
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 17057752
Are you sure you application is running after Explorer reloads? Did you checked it in Task Manager?
0
 
LVL 16

Author Comment

by:CodedK
ID: 17057820
Hi Ivanov_G .
Yes it runs.
And the big problem is that without those icons (2) there is no functionality !
0
 
LVL 17

Expert Comment

by:geobul
ID: 17057858
Hi,

Have you tried moving the mouse button over the tray? Is it possible the two icons to be among the hidden ones? (if there is < button).

Are you using a component (third-party) or API functions directly for adding the app in the tray? If you have coded that could you show the code?

Regards, Geo
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 28

Assisted Solution

by:2266180
2266180 earned 50 total points
ID: 17057878
that "bug" happens to be an explorer bug. as many others.

one way to go is to see when explorer is restarted and then recreate the icons. (hooks will be on this one, or a slow timer, say 1 check in a 1-3 or more seconds, though this approach will keep the cpu busy)
another way is to again check in a timer that the icons have valid handles (though this might be true). I never tried, but you could check to see exactly what becomes invalid after explorer restart.

best way to go is probably as described in this blog:
http://blogs.msdn.com/triballibrarian/archive/2004/06/25/166328.aspx
0
 
LVL 16

Author Comment

by:CodedK
ID: 17058098
Hi Geobul... Yes Api functions ...
Here is a small portion of the code:

~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
uses ..... ShellApi {For Tray notification definitions }

const
  WM_ICONTRAY=WM_USER+1;

  public
    { Public declarations }
    F1Tray:TNotifyIconData;
    F1Icon:TIcon;
    F2Tray:TNotifyIconData;
    F2Icon:TIcon;
....


procedure TForm1.FormCreate(Sender: TObject);
Begin

//Enable tray icon 1
With F1Tray do
 begin
  cbSize:=SizeOf(F1Tray);
  Wnd:=Handle;
  uID:=0;
  uFlags:=NIF_MESSAGE+NIF_ICON+NIF_TIP;
  uCallbackMessage:=WM_ICONTRAY;
  F1Icon:=TIcon.Create;
  Image.GetIcon(0,F1Icon);
  hIcon:=F1Icon.Handle;
  StrPCopy(szTip,'This is the first icon.');
 end;

Shell_NotifyIcon(NIM_ADD,@F1Tray);


//Enable tray icon 2
With F2Tray do
 begin
  cbSize:=SizeOf(F2Tray);
  Wnd:=Handle;
  uID:=1;
  uFlags:=NIF_MESSAGE+NIF_ICON+NIF_TIP;
  uCallbackMessage:=WM_ICONTRAY;
  F2Icon:=TIcon.Create;
  Image.GetIcon(0,F2Icon);
  hIcon:=F2Icon.Handle;
  StrPCopy(szTip,'This is the second icon');
 end;

Shell_NotifyIcon(NIM_ADD,@F2Tray);

end;

~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
Hi Ciuly... I've seen this happen many times with other programs.
But Explorer doesnt like my app at all... It always destroy the icons when it crash.
Interesting link.

I'll create a timer that will do something ONLY IF my app capture the message of TaskbarCreated...
This way i want use cpu power....

How can i do that ?
The article says the TaskbarCreated string and then broadcasts this message to all top-level windows.
Mine is minimized....

Thanks for any help :)
0
 
LVL 17

Accepted Solution

by:
geobul earned 200 total points
ID: 17058158
Hi again,

The following is a solution from another expert I haven't tried myself but it's worth:

type
 TForm1 = class(TForm)
   procedure FormCreate(Sender: TObject);
 private
   { Private-Deklarationen }
 protected
   FMsgTaskbarCreated : dword;
   procedure WndProc(var Message: TMessage); override;
 public
   { Public-Deklarationen }
 end;

var
 Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
 FMsgTaskbarCreated := RegisterWindowMessage('TaskbarCreated');
end;

procedure TForm1.WndProc(var Message: TMessage);
begin
 inherited;
 if Message.Msg = FMsgTaskbarCreated then
   Caption := Caption + '+';
end;

end.

Regards, Geo
0
 
LVL 16

Author Comment

by:CodedK
ID: 17058246
Thanks Geo it works in a way....

When i terminate explorer (with my app running) and then reload explorer
I get "System error 1400 - Invalid Window Handle"

I use the proc like that :

procedure TForm1.WndProc(var Message: TMessage);
begin
 inherited;
 if Message.Msg = FMsgTaskbarCreated then
 begin
   Shell_NotifyIcon(NIM_ADD,@F1Tray);
   Shell_NotifyIcon(NIM_ADD,@F2Tray);
 end;
end;
--------------------------------------------------

ONLY F2 Icon loads to the tray, this restores half the functionality of my app...
Why F1 doesnt load ?
0
 
LVL 16

Author Comment

by:CodedK
ID: 17058307
Strange... very strange

I've done the following :

procedure TForm1.WndProc(var Message: TMessage);
begin
 inherited;
 if Message.Msg = FMsgTaskbarCreated then
 begin
   //Enable tray icon 1
   With F1Tray do
    begin
     cbSize:=SizeOf(F1Tray);
     Wnd:=Handle;
     uID:=0;
     uFlags:=NIF_MESSAGE+NIF_ICON+NIF_TIP;
     uCallbackMessage:=WM_ICONTRAY;
     F1Icon:=TIcon.Create;
     Image.GetIcon(0,F1Icon);
     hIcon:=F1Icon.Handle;
     StrPCopy(szTip,'This is the first icon.');
    end;
     
Shell_NotifyIcon(NIM_ADD,@F1Tray);
     
  //Enable tray icon 2
  With F2Tray do
   begin
    cbSize:=SizeOf(F2Tray);
    Wnd:=Handle;
    uID:=1;
    uFlags:=NIF_MESSAGE+NIF_ICON+NIF_TIP;
    uCallbackMessage:=WM_ICONTRAY;
    F2Icon:=TIcon.Create;
    Image.GetIcon(0,F2Icon);
    hIcon:=F2Icon.Handle;
    StrPCopy(szTip,'This is the second icon');
  end;

Shell_NotifyIcon(NIM_ADD,@F2Tray);
 end;

end;


Now i dont get the "Invalid Window Handle" error !
But it only loads only the first paragraph !!!!!!!

If i put the icon1 paragraph first then it only loads paragraph1 else the second...
0
 
LVL 16

Author Comment

by:CodedK
ID: 17058320
It seems like when ever it likes it gives the error... I got again the "Invalid handle" error.
0
 
LVL 16

Author Comment

by:CodedK
ID: 17064063
Geo the procedure you gave works.
I should destroy first the icons.
But the message "System error 1400. Invalid Handle" appears every time.
Any ideas ?
0
 
LVL 16

Author Comment

by:CodedK
ID: 17067824
Thanks Geo and Ciuly :)
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

813 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now