Microsoft Office Tutorials and References
In Depth Information
A UserForm with No Title Bar
When the mouse button is pressed, the MouseDown event occurs, and the X and Y positions of
the mouse pointer are stored. Two public variables are used to keep track of the original position
of the controls: OldX and OldY . This procedure also changes the ZOrder property, which puts
the image “on top” of the others.
When the mouse is being moved, the MouseMove event occurs repeatedly. The event procedure
checks the mouse button. If the Button argument is 1, it means that the left mouse button is
depressed. If so, then the Image control is shifted relative to its old position.
Also, notice that the mouse pointer changes when it’s over an image. That’s because the
MousePointer property is set to 15 - fmMousePointerSizeAll . This mouse pointer style
is commonly used to indicate that something can be moved.
A UserForm with No Title Bar
Excel provides no direct way to display a UserForm without its title bar. But this feat is possible
with the help of a few API functions. Figure 15-14 shows a UserForm with no title bar.
Figure 15-14: This UserForm lacks a title bar.
Another example of a UserForm without a title bar is in Figure 15-15. This dialog box contains an
Image control and a CommandButton control.
Both of these examples are in a workbook named no title bar.xlsm , which is
available on the companion CD-ROM. The CD also contains another version of the splash
screen example presented in Chapter 14. This version, named splash screen2.xlsm ,
displays the UserForm without a title bar.
Displaying a UserForm without a title bar requires four windows API functions: GetWindowLong ,
SetWindowLong , DrawMenuBar , and FindWindowA (see the example file on the CD for the
function declaration). The UserForm_Initialize procedure calls these functions:
Private Sub UserForm_Initialize()
Dim lngWindow As Long, lFrmHdl As Long
lFrmHdl = FindWindowA(vbNullString, Me.Caption)
lngWindow = GetWindowLong(lFrmHdl, GWL_STYLE)
lngWindow = lngWindow And (Not WS_CAPTION)
Call SetWindowLong(lFrmHdl, GWL_STYLE, lngWindow)
Call DrawMenuBar(lFrmHdl)
End Sub
Search JabSto ::

Custom Search