Visual Basic Programming Code Examples Visual Basic > Applications VBA Code Examples Setting-Altering the Alt + Tab icon for an application (inc. MDI apps) Setting-Altering the Alt + Tab icon for an application (inc. MDI apps) 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 'Example/s : ' 'Set the application to have the same Icon as Excel ' TaskBarIconSet Form1.hwnd, , "C:\Program Files\Office\Excel.exe", 0 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 'Set the task bar icon for the topmost window SendMessage lHwndTopMost, WM_SETICON, ICON_BIG, ByVal lHwndIcon End Sub