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.
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.
| CD-ROM | Both of these examples are in a workbook named |
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
One problem is that, without a title bar, the user has no way to reposition the dialog box. The solution is to use the MouseDown and MouseMove events, as described in the preceding section.
| Note | Because the FindWindowA function uses the UserForm's caption, this technique will not work if the Caption property is set to an empty string. |