icon on userform

  • Thread starter Thread starter pswanie
  • Start date Start date
P

pswanie

is there a way i can put a icon in the blue bar next to the userform name?
 
hi
i don't think so. i think it violates the naming conviction. but if you have
it saved as an image, you can put it on the form. see the form's picture
property on the form's property sheet.

Regards
FSt1
 
Have a Userform with an Image control with in it the icon.
Get the icon in the control by clicking the file browser button in the
Picture property.
I don't think the properties of the Image control matter much, but Visible
would normally be False.

Then in the Userform have this code:


Option Explicit
Private Const ICON_SMALL = 0&
Private Const ICON_BIG = 1&
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As
Long, _
ByVal wParam As Long, lParam As Any)
As Long
Private Declare Function DrawMenuBar Lib "user32" _
(ByVal hwnd As Long) As Long


Private Sub UserForm_Initialize()


Dim hwnd As Long
Dim hIcon As Long


hIcon = Image1.Picture


If Val(Application.Version) >= 9 Then
hwnd = FindWindow("ThunderDFrame", Me.Caption)
Else
hwnd = FindWindow("ThunderXFrame", Me.Caption)
End If


If hwnd <> 0 Then
SendMessage hwnd, WM_SETICON, ICON_SMALL, ByVal hIcon
SendMessage hwnd, WM_SETICON, ICON_BIG, ByVal hIcon
DrawMenuBar hwnd
End If


End Sub



Then just load the form the normal way.


RBS
 
i get a compile error
variable not defined

at this part (the first "wm_seticon" are highlighted)

If hwnd <> 0 Then
SendMessage hwnd, WM_SETICON, ICON_SMALL, ByVal hIcon
SendMessage hwnd, WM_SETICON, ICON_BIG, ByVal hIcon
DrawMenuBar hwnd
End If
 
Sorry, I had left that constant out:

Private Const WM_SETICON = &H80

Put this at the other constants.

RBS
 
Thanx...

i get no errors now and the userform load. but the picture display in the
userform and i need it to show in the "blue" bar at the top next to the
userform caption...

is that possible?
 
need it to show in the "blue" bar

It does with me.
Could you post your code.

RBS
 
Option Explicit
Private Const ICON_SMALL = 0&
Private Const wm_seticon = &H80
Private Const ICON_BIG = 1&
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As
Long, _
ByVal wParam As Long, lParam As Any)
As Long
Private Declare Function DrawMenuBar Lib "user32" _
(ByVal hwnd As Long) As Long


Private Sub UserForm_Initialize()


Dim hwnd As Long
Dim hIcon As Long


hIcon = Image1.Picture


If Val(Application.Version) >= 9 Then
hwnd = FindWindow("ThunderDFrame", Me.Caption)
Else
hwnd = FindWindow("ThunderXFrame", Me.Caption)
End If


If hwnd <> 0 Then
SendMessage hwnd, wm_seticon, ICON_SMALL, ByVal hIcon
SendMessage hwnd, wm_seticon, ICON_BIG, ByVal hIcon
DrawMenuBar hwnd
End If


End Sub
 
Have copied your exact code and added it to a UserForm1
Added an Image control and added an icon.
Made the Image control invisible.
Added a normal module with this:

Sub start()

Load UserForm1
UserForm1.Show

End Sub

Ran this code and all working as it should.
What version of Excel do you have.
What kind of .ico file did you use?

RBS
 
wups....!!! that my problem.... what .ico file do i need? where do i put it?
where do i get it?
 
Any normal .ico file will do.
Add the image control (this shows as a mountain and a sun in my control
Toolbox and is called Image)
Then right-click the control and do Properties
Go to picture and select it and then press the browse button and find and
add your .ico file.
Should work now.

RBS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top