CodeItBetter Programming Another VB Programming Blog

How to Set an application’s Task Manager icon

Posted on January 4, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
'Forms - How to Set an application's Task Manager icon
'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
Filed under: Forms Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.