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

Related posts:

  1. How to Load an application’s form and Task Manager icons from a resource file
  2. How to find the user is trying to close the application using task manager or by pressing the X in Title bar, etc. How to restrict/refuse that
  3. How to cancel the user action when the user trying to close the application using task manager.
  4. How to show Windows Task Manager?
  5. How to hide your exe file from Task Manager Applications Tab
  6. Visual Basic 2008 – Task Manager
  7. Visual Basic 2008/2010 Task Manager Tutorial
  8. How to Enable/Disable Task Manager
  9. How to close the child windows in an external application.
  10. How to check if a task exists by searching for (part or all of) the window title

Filed under: Forms Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


No trackbacks yet.