Home
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
 
 
Old Pages
 
Old Index
Site Map
What's New
 
Books
How To
Tips & Tricks
Tutorials
Stories
Performance
Essays
Links
Q & A
New in VB6
Free Stuff
Pictures
 
 
 
 
 
 
 
TitleLoad an application's form and Task Manager icons from a resource file
Keywordsicon, application icon, task manager, resource file
CategoriesGraphics
 
Subroutine SetApplicationIcons uses LoadResPicture to load the form's icon from a resource file.

Then the routine loads the application's icon into a PictureBox. It uses TopmostWindowHandle to find the application's topmost window. Finally it uses SendMessage to set that window's big icon to the image loaded in the PictureBox. That sets the application icon for the Task Manager.

 
' Load the application's form and application icons
' from a resource file.
Private Sub SetApplicationIcons()
Dim hIcon As Long
Dim app_hwnd As Long

    ' Load the form's icon.
    Me.Icon = LoadResPicture("FORMICON", vbResIcon)

    ' Load the big icon and get its handle.
    picBigIcon.AutoRedraw = True
    picBigIcon.AutoSize = True
    picBigIcon.Visible = False
    picBigIcon.Picture = LoadResPicture("APPICON", _
        vbResIcon)
    hIcon = picBigIcon.Picture

    ' Set the big icon for the topmost window.
    app_hwnd = TopmostWindowHandle(Me)
    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-2001 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated