Z
zz
I have the following code, this is use to apply a style to my userforms, so
it gets a controlbox like the regular Vb forms, it also inserts an icon in
the userform's caption.
My question is, is it really necessary that the hIcon be the result of the
ExtractIcon function?
instead, how could i pass an .ico file as a parameter so i can use my own
custom .ico file in each useform?
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA"
(ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As
Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA"
(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal
lParam As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA"
(ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA"
(ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA"
(ByVal hWnd As Long, ByVal lpString As String) As Long
Public Function Apply_Style(formcaption As String, iconnum As Integer)
Dim hWnd, eWnd As Long
Dim hIcon As Long
Dim f_style As Long
'Form window
hWnd = FindWindow("ThunderDFrame", formcaption)
'Application window
eWnd = FindWindow("XLMAIN", Application.Caption)
'Grab the icon from shell32.dll...
hIcon = ExtractIcon(0, "SHELL32.DLL", iconnum)
'draw the icon
SendMessage hWnd, &H80, True, hIcon
SendMessage hWnd, &H80, False, hIcon
f_style = GetWindowLong(hWnd, -16)
f_style = f_style Or &H30000 'system toolbox
f_style = f_style Or &H20000 'minimize
f_style = f_style Or &H10000 'maximize
SetWindowLong hWnd, -16, f_style
End Function
i use the function as follows apply_style me.caption, 16
' where " me.caption" is the caption of the current userform, and "16 " is
the index of the icon in the shell.dll icons list.
it gets a controlbox like the regular Vb forms, it also inserts an icon in
the userform's caption.
My question is, is it really necessary that the hIcon be the result of the
ExtractIcon function?
instead, how could i pass an .ico file as a parameter so i can use my own
custom .ico file in each useform?
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA"
(ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As
Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA"
(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal
lParam As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA"
(ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA"
(ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA"
(ByVal hWnd As Long, ByVal lpString As String) As Long
Public Function Apply_Style(formcaption As String, iconnum As Integer)
Dim hWnd, eWnd As Long
Dim hIcon As Long
Dim f_style As Long
'Form window
hWnd = FindWindow("ThunderDFrame", formcaption)
'Application window
eWnd = FindWindow("XLMAIN", Application.Caption)
'Grab the icon from shell32.dll...
hIcon = ExtractIcon(0, "SHELL32.DLL", iconnum)
'draw the icon
SendMessage hWnd, &H80, True, hIcon
SendMessage hWnd, &H80, False, hIcon
f_style = GetWindowLong(hWnd, -16)
f_style = f_style Or &H30000 'system toolbox
f_style = f_style Or &H20000 'minimize
f_style = f_style Or &H10000 'maximize
SetWindowLong hWnd, -16, f_style
End Function
i use the function as follows apply_style me.caption, 16
' where " me.caption" is the caption of the current userform, and "16 " is
the index of the icon in the shell.dll icons list.