VB and VBA Users Source Code: Setting/Altering the Alt + Tab icon for an application (inc. MDI apps)
[
Home
|
Contents
|
Search
|
Reply
| Previous | Next ]
VB/VBA Source Code
Setting/Altering the Alt + Tab icon for an application (inc. MDI apps)
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Wednesday, October 22, 2003
Hits:
1078
Category:
Windows Forms/GUI/Controls/Graphics
Article:
The code below can be used to dynamically set the Alt + Tab icon for an application. Option Explicit Private Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" (ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As Long Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long 'Purpose : Sets the Alt+Tab icon for an application (inc. MDI forms as well) 'Inputs : lFormHwnd The handle the a form within the application ' [lHwndIcon] The handle to the icon ' [sIconPath] If not specifying [lHwndIcon] then use the parameter to ' specify the path to a file containing an icon (eg. and EXE). ' [lIconIndex] If specified [sIconPath] then use the to specify the index of the icon ' to load 'Outputs : N/A 'Author : Andrew Baker (www.vbusers.com) 'Date : 31/Jan/2002 'Example/s : ' 'Set the application to have the same Icon as Excel ' TaskBarIconSet Form1.hwnd, , "C:\Program Files\Office\Excel.exe", 0 'Revisions : Sub TaskBarIconSet(lFormHwnd As Long, Optional lHwndIcon As Long, Optional sIconPath As String, Optional lIconIndex As Long = 0) Const WM_GETICON = &H7F, WM_SETICON = &H80, ICON_BIG = 1, GWL_HWNDPARENT As Long = (-8) Dim lHwndTopMost As Long, lTestHwnd As Long If lHwndIcon = 0 Then 'Get the handle to the icon lHwndIcon = ExtractIcon(0, sIconPath, lIconIndex) End If ' Get the topmost window handle lHwndTopMost = lFormHwnd lTestHwnd = GetWindowLong(lFormHwnd, GWL_HWNDPARENT) Do While lTestHwnd <> 0 lHwndTopMost = lTestHwnd lTestHwnd = GetWindowLong(lHwndTopMost, GWL_HWNDPARENT) Loop If lHwndTopMost Then 'Set the task bar icon for the topmost window SendMessage lHwndTopMost, WM_SETICON, ICON_BIG, ByVal lHwndIcon End If End Sub
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder