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.

image from book
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.

image from book
Figure 15-15: Another UserForm without a title bar.
CD-ROM  

Both of these examples are in a workbook named image from book  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 image from book  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 

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.




Excel 2007 Power Programming with VBA
Excel 2007 Power Programming with VBA (Mr. Spreadsheets Bookshelf)
ISBN: 0470044012
EAN: 2147483647
Year: 2007
Pages: 319

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net