Solved

Repair missing tray icon.

Posted on 2006-07-07
11
497 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
[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
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
Industry Leaders: 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!

 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month2 days, 18 hours left to enroll

622 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