Thread: Userform Icon
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
RB Smissaert RB Smissaert is offline
external usenet poster
 
Posts: 2,452
Default Userform Icon

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



"gti_jobert" wrote
in message ...

Hello,

How do you set an icon/bitmap in the caption field of a userform?

Thanks all..


--
gti_jobert
------------------------------------------------------------------------
gti_jobert's Profile:
http://www.excelforum.com/member.php...o&userid=30634
View this thread: http://www.excelforum.com/showthread...hreadid=521752