With this code you can place any Icon in the title bar of any Window, just by reffering to a .ico file or to the position of the Icon in a DLL.
Original Author: J. van Gils
Inputs
Handle of the window you want to change the icon of.
Assumptions
You need to have the Window Handle (hWnd) of the window whitch Icon you want to change. This can be done by searching/finding it with the API-call
Declare Function FindWindowEx Lib “user32” Alias “FindWindowExA” (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Side Effects
none (that I know of)
API Declarations
Declare Function ExtractIcon Lib “shell32.dll” Alias “ExtractIconA” (ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As Long
Declare Function DefWindowProc Lib “user32” Alias “DefWindowProcA” (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Const WM_SETICON = &H80
Code
Public Function SetIcon(FormhWnd As Long)
Dim x, i As Long
i = ExtractIcon(0, "c:SomeDll.DLL", 3)
'In this case you will extract the 3rd icon from SomeDll.DLL. In this
'way you can extract any icon you want, just by reffering to the icon
'(number) of the icon you want to extract in the dll. If you want to
'know the iconnumbers of a dll, you will have to use a recource editor
'(like Borland Recource Workshop). You can also extract the Icon Handle
'of a .ico file just by using some code like:
'i=ExtractIcon(0,"c:SomeIconFile.ico",0)
'where SomeIconFile is the name of the icon you want to use.
'Now finally set the icon in the title bar of the window
x = DefWindowProc(FormhWnd, WM_SETICON, &H1, i)
End Function