Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trouble with the Icons in the Taskbar 1

Status
Not open for further replies.

Leonardozwei

Programmer
Jun 24, 2002
15
I want to make an Application, that send to the windows-IconTaskBar when it the window is minimized.

with the function

procedure TForm1.IconTaskBar_show(Icon:TIcon; Hint:string);
var vIconTaskBar : TNotifyIconData;
begin
Hint := copy(Hint, 1, 63); // maximum size of the hint-field
With vIconTaskBar do
begin
cbSize:=SizeOf(vIconTaskBar);
Wnd:=Handle;
uID:= 1; // we use only one Icon in the Taskbar
uFlags:= NIF_ICON Or NIF_MESSAGE Or NIF_TIP;
uCallbackMessage:=WM_IconTaskBar_Notify; // Message-ID sended to notify Icon-events
hIcon:=Icon.Handle; // The Icon to Show
StrPCopy(szTip, Hint);
end;
Shell_NotifyIcon(NIM_ADD, @vIconTaskBar);
FIconTaskBar_Visible := true;
end;

it is Called like this

IconTaskBar_show(Application.Icon, 'ISDN-View');
Hide; // hide the Main-Form

this works so far, but now I want to exchange the Icon with another... this function should do this...

procedure TForm1.IconTaskBar_Modify(NewIcon:TIcon; Hint:string);
var vIconTaskBar : TNotifyIconData;
begin
Hint := copy(Hint, 1, 63); // maximum size of the hint-field
With vIconTaskBar do
begin
cbSize:=SizeOf(vIconTaskBar);
Wnd:=Handle;
uID:= 1; // we use only one Icon in the Taskbar
uFlags:= NIF_ICON Or NIF_TIP;
uCallbackMessage:=WM_IconTaskBar_Notify; // Message-ID sended to notify Icon-events
hIcon:=Icon.Handle; // The Icon to Show
StrPCopy(szTip, Hint);
end;
Shell_NotifyIcon(NIM_MODIFY, @vIconTaskBar);
end;

it is called like this

if Icons[B1, B2] = nil then
begin
Icons[B1, B2] := TIcon.Create;
try
Icons[B1, B2].LoadFromFile(fn);
finally
end;
end;
Application.Icon := Icons[B1, B2];
IconTaskBar_Modify(Icons[B1, B2], 'ISDN-View');

B1 and B2 are the the differnt states, that the Tray-Icon should visulized.

Now the Problem:

When the Icon should change, it simply disapear, or better the Place where the icon should bee is empty. When I click on the Empty place in the Icon-Tray it sends Notification-Messages to my aplication, so it is still there, but with no image.

what's wrong? Can anybody help me?

Leonardo
 
Hope this helps.
I have a program that does something liek what you are after. I start with a res file with all the different colours I want so

implementation
{$R *.DFM}
{$R RYS.RES}
{mhs_2_SMTP : interfase}


Then in the create statement of the form I have this code

Icon.Handle := LoadIcon(HInstance, 'Green');
nid.cbSize := sizeof(nid);
nid.wnd := Handle;
nid.uID := 1;
nid.uCallBackmessage := wm_IconMessage;
nid.hIcon := Icon.Handle;
nid.szTip := 'EziBuy Gateway';
nid.uflags := nif_message or
nif_icon or nif_tip;
Shell_NotifyIcon(NIM_ADD,@nid);

Then the procedures to change the colours are

procedure TMHS2SMTP.ChangeIconYellow();
begin
Icon.Handle := LoadIcon(HInstance, 'Yellow');
nid.hIcon := Icon.Handle;
nid.uFlags := nif_Icon or nif_tip;
Shell_NotifyIcon(NIM_MODIFY,@nid);
end;


//------------------------------------------------------------------------------
//Changes the colour of the icon Green

procedure TMHS2SMTP.ChangeIconGreen();
begin
Icon.Handle := LoadIcon(HInstance, 'Green');
nid.hIcon := Icon.Handle;
nid.uFlags := nif_Icon or nif_tip;
Shell_NotifyIcon(NIM_MODIFY,@nid);
end;




 
Thanks,

your code helped me to find my mistake. It was is simple misnamed Variable (damt copy & paste ;-) )... As Parameter I used NewIcon... and in the codeblock I wrote

hicon := Icon.handle

I changed it to

hicon := NewIcon.handle

and everything works fine.

again thanks for the answer
Leonardo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top