Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Repair missing tray icon.

Posted on 2006-07-07
11
Medium Priority
?
499 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
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 28

Assisted Solution

by:2266180
2266180 earned 200 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 800 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

886 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