VBcoders Browse New Submit Contact Sign In

No account? Register free

Forgot password?

Get a hWnd's Icon Handle

SKoW  (11 Submissions)   Windows API Call/Explanation   Visual Basic 3.0   Advanced   Wed 3rd February 2021

This basicly tries to find the small icon for a window (the icon on the top left). Note: it returns the HANDLE to the icon, good for using in API calls. Also, I have looked around and there is NOTHING about this posted anywhere. That is why I'm posting it. (this is part of my current app...)

Inputs
hWnd - the Handle of the Window to check (ie form1.hwnd)

Assumes
Place code in a module file (and name it something like wIcon)

Returns
Returns Handle to the icon of the hWnd being checked.

API Declarations
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long
Private Declare Function GetClassLong Lib "user32" Alias "GetClassLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hWnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function GetClassInfo Lib "user32" Alias "GetClassInfoA" (ByVal hInstance As Long, ByVal lpClassName As String, lpWndClass As WNDCLASS) As Long
Private Declare Function GetClassInfoEx Lib "user32" Alias "GetClassInfoExA" (ByVal hInstance As Long, ByVal lpClassName As String, lpWndClass As WNDCLASSEX) As Long
Private Type WNDCLASSEX ' Same as WNDCLASS but has a few advanced values
cbSize As Long
style As Long
lpfnwndproc As Long
cbClsextra As Long
cbWndExtra As Long
hInstance As Long
hIcon As Long ' Handle to large icon (Alt-Tab icon)
hCursor As Long
hbrBackground As Long
lpszMenuName As String
lpszClassName As String
hIconSm As Long ' Handle to Small icon (Top Left Icon/Taskbar Icon)
End Type
Private Type WNDCLASS
style As Long
lpfnwndproc As Long
cbClsextra As Long
cbWndExtra2 As Long
hInstance As Long
hIcon As Long ' Handle to icon (only 1 size)
hCursor As Long
hbrBackground As Long
lpszMenuName As String
lpszClassName As String
End Type
Private Const GWL_HINSTANCE = -6 ' For GetWindowLong(..)
Private Const GCL_HICON = -14 ' For GetClassLong(..)
Private Const WM_GETICON = &H7F

Rate Get a hWnd's Icon Handle (3(3 Vote))
Get a hWnd's Icon Handle.bas

Get a hWnd's Icon Handle Comments

No comments yet — be the first to post one!

Post a Comment

0/1000 characters