Home » Forms » How to Load an application’s form and Task Manager icons from a resource file
How to Load an application’s form and Task Manager icons from a resource file
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 35 36 37 38 39 40 41 42 43 44 | 'Forms - How to Load an application's form and Task Manager icons from a resource file '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. 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. With picBigIcon .AutoRedraw = True .AutoSize = True .Visible = False .Picture = LoadResPicture("APPICON", vbResIcon) hIcon = .Picture End With ' 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 |
Enjoy this article?
Filed under: Forms
Leave a comment