×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

VB UserForm with Icon in TitleBar

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

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

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


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

Florent,

I will have to give it a try.

Regards,

Regg

RE: VB UserForm with Icon in TitleBar

(OP)
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

RE: VB UserForm with Icon in TitleBar

(OP)
The main thing is to succeed in understanding ourselves.

2thumbsup

SW2007 SP5
Worksatation HP wx4300 2GB
NVidia Quadro FX 3450

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources