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 Loading graphic into top left strip of userform

This how you can do that:

Have a userform, UserForm1, with an image control, Image1. This control will
show in the control toolbox as Picture.

In the properties of the image control find the property Picture and in the
values column browse to an .ico file of your choice.
You could set the property Visible of this image control to False.

In the UserForm events, in the initialize event put this:

Option Explicit

Private Sub UserForm_Initialize()
LoadPicture
End Sub


Then in a normal module put all this code:

Option Explicit
Public 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 Integer, _
ByVal lParam As Long) As Long

Public Declare Function DrawMenuBar Lib "user32" _
(ByVal hwnd As Long) As Long

Private Const WM_SETICON = &H80
Private Const ICON_SMALL = 0&
Private Const ICON_BIG = 1&

Sub LoadForm()

Load UserForm1
UserForm1.Show

End Sub

Sub LoadPicture()

Dim hIcon As Long
Dim hwnd As Long

With UserForm1

hIcon = .Image1.Picture

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

If hwnd = 0 Then
Exit Sub
Else
SendMessage hwnd, WM_SETICON, ICON_SMALL, ByVal hIcon
SendMessage hwnd, WM_SETICON, ICON_BIG, ByVal hIcon
DrawMenuBar hwnd
End If

End With

End Sub

Then run the Sub LoadForma and there is your userform with icon.


RBS


"ExcelMonkey" wrote in message
...
How do you load an image into the top left hand cornder of a userform.
For
example all userforms have the small coloured trip that runs from top left
to
right. How do you load a small icon intot the top left of that strip?

Thanks