Using the CAbout Class


All you need to create your own About dialog box is to write some code in the event procedure from the About menu of the All About program, as shown in the following sample:

Private Sub mnuAbout_Click()
Dim about As New CAbout
With about
On Error GoTo FailAbout
' Set properties
Set .Client = App
Set .Icon = Forms(0).Icon
.UserInfo(2) = "Don't even think " & _
"about stealing this program"
' Load after all properties are set
.Load
' Modal form will return here when finished
Exit Sub
End With
FailAbout:
MsgBox "I don't know nuttin'"
End Sub

Figure 11-2 shows the results.



Figure 11-2. About All About.


You create and load a CAbout object, but what you see is the FAbout form. Forms can’t be public in a component (such as VBCore), so you have to wrap the internal form in a public class. Actually, I think of this as a benefit, not a burden. If you could expose a form without a wrapper, clients would get ­access to all the properties and events of the form. It wouldn’t be an About form if the user could modify anything through the standard form methods and properties.


The CAbout class gets its information from several sources. You pass an App object through the Client property to provide the title and other infor­-
mation about the program. You can pass an icon through the Icon property. The UserInfo array property lets you enter three lines of general text information. The example provides only one line, but puts it in position 2 of the array so that it will be centered. The InfoProg, Copyright, and Comments properties (not used in the sample) allow you to override information that the form ordinarily figures out from the Client property. Additional system information comes from the System object described in “The CSystem Class and the System Object” later in this chapter. The form gets its undocumented animation command from...well, if I told you, it wouldn’t be undocumented.


After you set the properties you want displayed, call the Load method to make the form appear. Unlike the wrapping forms of most classes, the CAbout class doesn’t return any information from the user, so there’s no need to check properties after the form terminates.


Unlike most of the classes in this book, CAbout and its FAbout form aren’t in VBCore. They’re in a separate component called VisualCore, along with all the other classes that wrap forms and thus have a user interface. That’s so that VBCore can be marked for Unattended Execution, a subject I’ll discuss in the “Threads and Synchronization” section later in this chapter. The other visual classes in VisualCore include CColorPicker (discussed later in this chapter) and COpenPictureFile (used by the Fun ’n Games program).