VB UserForm with Icon in TitleBar
VB UserForm with Icon in TitleBar
(OP)
Hi,
If you want to add an icon in your VBA UserForm ; the same one than your button in toolbar for example.
You can add this code in UserForm's code.
Add this code at the begining of the code
Then we can add the Initialize sub or add this text in the existing one.
The result :

I hope this tip will be useful !
If you want to add an icon in your VBA UserForm ; the same one than your button in toolbar for example.
You can add this code in UserForm's code.
Add this code at the begining of the code
CODE
' first we declare some external used functions
Private Declare Function FindWindow Lib "user32" Alias _
"FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SendMessageA Lib "user32" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, _
ByVal lParam As Long) As Long
Private Declare Function ExtractIconA Lib "shell32.dll" _
(ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias _
"FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SendMessageA Lib "user32" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, _
ByVal lParam As Long) As Long
Private Declare Function ExtractIconA Lib "shell32.dll" _
(ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As Long
Then we can add the Initialize sub or add this text in the existing one.
CODE
' Initialise UserForm with icon
Private Sub UserForm_Initialize()
Dim uFile As String
Dim x As Long
'Full path of the picture (UNC works too)
uFile = "C:\MyPicture.bmp"
' Check if the picture file really exists, if not -> termine the sub
' Be careful if you have code behind this (maybe goto)
x = Len(Dir(uFile ))
If x = 0 Then Exit Sub
'Extract icon from picture file, and put it in the TitleBar
x = ExtractIconA(0, uFile , 0)
SendMessageA FindWindow(vbNullString, Me.Caption), &H80, False, x
End Sub
Private Sub UserForm_Initialize()
Dim uFile As String
Dim x As Long
'Full path of the picture (UNC works too)
uFile = "C:\MyPicture.bmp"
' Check if the picture file really exists, if not -> termine the sub
' Be careful if you have code behind this (maybe goto)
x = Len(Dir(uFile ))
If x = 0 Then Exit Sub
'Extract icon from picture file, and put it in the TitleBar
x = ExtractIconA(0, uFile , 0)
SendMessageA FindWindow(vbNullString, Me.Caption), &H80, False, x
End Sub
The result :
I hope this tip will be useful !
SW2007 SP5
Worksatation HP wx4300 2GB
NVidia Quadro FX 3450






RE: VB UserForm with Icon in TitleBar
I will have to give it a try.
Regards,
Regg
RE: VB UserForm with Icon in TitleBar
Matt Lorono
CAD Engineer/ECN Analyst
Silicon Valley, CA
Lorono's SolidWorks Resources
Co-moderator of Solidworks Yahoo! Group
and Mechnical.Engineering Yahoo! Group
RE: VB UserForm with Icon in TitleBar
sorry for my bad English but, I don't understand what you mean by "Autoloading".
The icon is loaded dynamicly. Is that what you wanted to say ?
In my case, I use the same picture for the button toolbar and the icon in title bar.
For your second question, I really don't understand ...
And for the last one, did you want to add a toolbar in your VB form or in SolidWorks windows ?
SW2007 SP5
Worksatation HP wx4300 2GB
NVidia Quadro FX 3450
RE: VB UserForm with Icon in TitleBar
Matt Lorono
CAD Engineer/ECN Analyst
Silicon Valley, CA
Lorono's SolidWorks Resources
Co-moderator of Solidworks Yahoo! Group
and Mechnical.Engineering Yahoo! Group
RE: VB UserForm with Icon in TitleBar
RE: VB UserForm with Icon in TitleBar
Matt Lorono
CAD Engineer/ECN Analyst
Silicon Valley, CA
Lorono's SolidWorks Resources
Co-moderator of Solidworks Yahoo! Group
and Mechnical.Engineering Yahoo! Group
RE: VB UserForm with Icon in TitleBar
SW2007 SP5
Worksatation HP wx4300 2GB
NVidia Quadro FX 3450