Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB UserForm with Icon in TitleBar

Status
Not open for further replies.

Florent

Mechanical
Feb 18, 2007
32
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
Code:
[COLOR=green]' first we declare some external used functions[/color]
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:
[COLOR=green]' Initialise UserForm with icon[/color]
Private Sub UserForm_Initialize()
    Dim uFile As String
    Dim x As Long
    
    [COLOR=green] 'Full path of the picture (UNC works too) [/color]
    uFile = "C:\MyPicture.bmp"
    [COLOR=green]' Check if the picture file really exists, if not -> termine the sub
    ' Be careful if you have code behind this (maybe goto)  [/color]
    x = Len(Dir(uFile ))
    If x = 0 Then Exit Sub
    [COLOR=green]'Extract icon from picture file, and put it in the TitleBar [/color]
    x = ExtractIconA(0, uFile , 0)
    SendMessageA FindWindow(vbNullString, Me.Caption), &H80, False, x
End Sub


The result :
download.aspx


I hope this tip will be useful !

SW2007 SP5
Worksatation HP wx4300 2GB
NVidia Quadro FX 3450
 
Florent,

I will have to give it a try.

Regards,

Regg
 
fcsuper ;

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
 
I was just suggesting that it is easier to add an icon to the toolbar using the SolidWorks built in customization abilities, rather than using API. I'm not sure why you'd want to dynamically add an icon to the toolbar.

Matt Lorono
CAD Engineer/ECN Analyst
Silicon Valley, CA
Lorono's SolidWorks Resources
Co-moderator of Solidworks Yahoo! Group
and Mechnical.Engineering Yahoo! Group
 
The main thing is to succeed in understanding ourselves.

[2thumbsup]

SW2007 SP5
Worksatation HP wx4300 2GB
NVidia Quadro FX 3450
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor