Link to home
Start Free TrialLog in
Avatar of shacho
shacho

asked on

Changing Taskbar Icons

Is there any way to change the icon displayed on the left side of a taskbar button?  I can get the window handle, but
SendMessage(hWnd, WM_SETICON, ICON_SMALL, ByVal hIcon) does not seem to have any effect.

Mike
Avatar of Rajesh Dalmia
Rajesh Dalmia
Flag of India image

which icon you are refering as "left side of a taskbar button". do u have any application whose icon you want to change or something else.
Avatar of shacho
shacho

ASKER

The Task Bar (i.e. the ToolbarWindow32 container sandwiched between the Start Button and the System Tray) contains one or more buttons for each open application.  Each button contains the application icon and the window name.  I want to change the icon.  Also, I was wrong about beign able to get the window handle.  I can only get the handle of the Task Bar itself.

Mike
The icon is associated with the application itself, basically that has nothing to do with the taskbar unless you only want to change the icon when it is actually minimized to the taskbar. If you want to change the icon than you do so by changing the applications icon.
The icon displayed on the taskbar is the icon of the form, so to update it you simply change that icon through code.  For example:

1. create a new exe project
2. set the icon for form1
3. add an image control to the form
4. set the picture property of the image to a different icon
5. add a command button to the form
6. add this code to the command button:

Private Sub Command1_Click()
    Set Me.Icon = Image1.Picture
End Sub

Run it.  The icon initially on the taskbar button is the form1 icon.  Now click the command button, and you will see the icon changes to the icon stored in the image control.

HTH-Jon
Avatar of shacho

ASKER

Interesting.  I'll give it a try.

Mike
Avatar of shacho

ASKER

I'm afraid it didn't work.  This is a VBA form hosted by Excel.  The tab is inheriting the icon from Excel.  I have tried setting the icon for both the form and Application with Application.hWnd.  In all four cases (ICON_BIG and ICON_SMALL) the function returns non-zero longs so something is happening.  In the case of the form, the form's icon does in fact change.  ...But not the tab's.  I should add that I'm forcing the tab to appear with Win API functions as VBA userforms don't normally appear in the taskbar.

Mike

you should try to change the icon of the parent of application.hwnd
Avatar of shacho

ASKER

Mark,

Thanks for the comment.  There is no parent object.  Application.hWnd is the same as Application.Parent.hWnd because the parent object of Excel is Excel.

Mike
ASKER CERTIFIED SOLUTION
Avatar of Wayne Taylor (webtubbs)
Wayne Taylor (webtubbs)
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of shacho

ASKER

I see.  That is almost exactly the code I was using, but the image control contains a pasted jpeg.
Perhaps that's why it didn't work.  I'll try it with an icon file.

Mike
Avatar of shacho

ASKER

Wayne, you're a genius.  Thank you very much indeed.

Mike
:) No problems Mike. Glad to help.