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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

application icon troubles

Status
Not open for further replies.

gusset

Technical User
Mar 19, 2002
251
0
0
GB
my add-in sets the application icon to an icon of my choosing when it runs, as per the following standard code. i have two questions:

1. the icon change works for the application in the top-left part of the application window and for the small window which appears when the Excel taskbar button is pressed. but it doesn't change the icon on the taskbar itself - can this be changed, please?

2. how can i change the icon back to its original state (the standard Excel icon)? presumably the standard windows icons are all stored in a particular folder and i can just point to this?

many thanks

gusset

Sub SetApplicationIcon(strIconPath As String)
Dim hWnd As Long
Dim hIcon As Long

'get the handle of the Excel window
hWnd = FindWindow("XLMAIN", ActiveWorkbook.Application.Caption)
'get the icon from the source file
hIcon = ExtractIcon(0, strIconPath, 0)
'1 means invalid icon source, 0 means no icons in source

If hIcon >= 1 Then
'set the 32x32 and 16x16 icons
SendMessage hWnd, WM_SetIcon, True, hIcon
SendMessage hWnd, WM_SetIcon, False, hIcon
End If
End Sub
 
1) To Set your Icon to the taskBar you need to refresh the
windows....you do this by hiding and display it via the API call ShowWindow

Code:
Private Declare Function ShowWindow _
    Lib "user32" ( _
    ByVal hWnd As Long, _
    ByVal nCmdShow As Long) _
As Long

Then use ....

ShowWindow hwnd, 0

your SendMessage code etc

ShowWindow hwnd, 1

I have hardcoded the constants

Q2. Just restore back via reference to Excel.exe file

eg
Code:
Const strStdXlicon As String = "C:\Program Files\Microsoft Office\Office\exel.exe"

hIcon = ExtractIcon(0, strStdXlicon, 0)

Don't forget to Use ShowWindow API for this as well otherwise it won't take




Ivan F Moala
 
thanks, IvanMoala, for both tips.

i ought to have got the second one myself though! btw, i notice that the location changes according to the platform. on this (xp) machine (with Office XP), the path is "C:\Program Files\Microsoft Office\Office10". i wonder whether there is a way to grab the correct location using vb?

best wishes

gusset
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top