Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleSet an application's Task Manager icon
Description
Keywordsicon, application icon, task manager
CategoriesGraphics, Windows
 
To set a form's icon, open the form in design mode, click the ellipsis next to its Icon property, and select the form's icon.

Unfortunately that doesn't set the program's icon in the Task Manager (what you see when you press Alt-Tab).

The SetApplicationIcon subroutine calls TopmostWindowHandle to find the application's topmost window. Then it uses SendMessage to set that window's big icon to an image handle. That sets the application icon for the Task Manager.

 
' Set the application's icon in the task bar.
Public Sub SetApplicationIcon(ByVal hIcon As Long)
Dim app_hwnd As Long

    ' Get the topmost window's handle.
    app_hwnd = TopmostWindowHandle(Me)

    ' Set the application's icon.
    SendMessage app_hwnd, WM_SETICON, ICON_BIG, ByVal hIcon
End Sub

' Return this window's topmost window's handle.
Private Function TopmostWindowHandle(ByVal frm As Form) As _
    Long
Dim status As Long
Dim app_hwnd As Long

    ' Get the topmost window's handle.
    status = GetWindowLong(frm.hWnd, GWL_HWNDPARENT)
    Do While status <> 0
       app_hwnd = status
       status = GetWindowLong(app_hwnd, GWL_HWNDPARENT)
    Loop

    TopmostWindowHandle = app_hwnd
End Function
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated