Solved

Repair missing tray icon.

Posted on 2006-07-07
11
490 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

919 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

18 Experts available now in Live!

Get 1:1 Help Now