Visual C++® 6 Unleashed
by Mickey Williams; David Bennett
http://www.informit.com/library/library.aspx?b=Visual_C_PlusPlus
Publisher: Sams
Pub Date: July 24, 2000
Print ISBN-10: 0-672-31241-7
Print ISBN-13: 978-0-672-31241-0
Pages: 1000
From this Chapter:
Chapter 28. ActiveX Controls
Extract:
ActiveX Controls > ActiveX Control Architecture
ActiveX Control Architecture
The beauty of ActiveX controls is that they are programmable and reusable. They expose themselves to the outside world and can be used in a variety of environments. ActiveX controls are similar to embedded object servers, in that they are embedded in a container and are responsible for providing a user interface. ActiveX controls also are expected to expose functionality through interfaces, which often are derived from IDispatch to take advantage of automation. ActiveX controls take advantage of the capability to send events to their container; this capability to send events separates ActiveX controls from other in-process OLE servers.
ActiveX controls communicate with the outside world in three ways:
Properties
Methods
Events
Properties
Properties are named attributes or characteristics of an ActiveX control. Properties may be marked as read-only, but typically these properties can be set or queried. Some examples of properties are color, font, and number.
Usually, ActiveX controls provide access to their properties through property sheets. Property sheets are exposed via automation. Property sheets are not limited to design/compile time but can be displayed at runtime to allow the user to manipulate the control's properties, events, or methods. Property sheets are user-interface components that basically are tabbed dialog boxes. Automation provides the mechanism by which ActiveX controls communicate with their property sheets.
ActiveX controls have access to what are called stock properties. These are properties common to all ActiveX controls. MFC enables you to take advantage of these stock properties because they already are built in. Table 28.1 lists all the stock properties supported by MFC.
Table 28.1. Stock Properties for ActiveX Controls Supported by MFC
Stock Property Get/Set Stock Method Enables You To…
Appearance void SetAppearance (short sAppear) short GetAppearance( ) Set the appearance of an ActiveX control to flat or 3D.
BackColor OLE_COLOR GetBackColor ( ) void SetBackColor (OLE_COLOR dwBkColor) Set the background colors of the control.
Border Style short GetBorderStyle ( ) void SetBorderStyle(short sBorderStyle) Set the border style of the control to normal or none.
Caption BSTR GetText( ) void SetText(LPCTSTR pszText) Set the caption of the ActiveX control.
Enabled BOOL GetEnabled( ) void SetEnabled(BOOL bEnabled) Enable or disable the control.
Font LPFONTDISP GetFont( ) void SetFont(LPFONTDISP pFontDisp) Set the font properties used by the control.
Fore Color OLE_COLOR GetForeColor( ) void SetForeColor(OLE_COLOR dwForeColor) Set the forecolors of the control.
hWnd OLE_HANDLE GetHwnd( ) Hold the control's window handle.
Ready State long GetReadyState( ) Get or set the ready state of the control with the following values: READYSTATE_UNINITIALIZED READYSTATE_LOADING READYSTATE_LOADED READYSTATE_INTERACTIVE READYSTATE_COMPLETE
Text const CString& InternalGetText( ) Get and set the control's text. This property is the same as Caption.
You can include the stock properties in your ActiveX controls by using the ClassWizard. Choose View, ClassWizard or press Ctrl+W. After the ClassWizard appears, select the Automation tab (see Figure 28.1).
Figure 28.1. Using the ClassWizard to access stock properties.
Click the Add Property button to invoke the Add Property dialog box. If you use the External Name combo box, you can select which stock properties you want your control to have (see Figure 28.2).
Figure 28.2. You can select stock properties to support by using the External Name combo box.
MFC and Visual C++ 6.0 also provide stock property sheets to add to our user interface so that users can set stock properties. These are General (see Figure 28.3), Fonts (see Figure 28.4), Colors (see Figure 28.5), and Pictures properties.
Figure 28.3. The default General Properties page.
Figure 28.4. The stock Fonts Properties page.
Figure 28.5. The stock Colors Properties page.
Note
Although the General property page is added to your control by default, it doesn't contain any controls. You must add the controls for this page yourself.
I also found the following
about half way down this page:::
Visual Basic Private Interfaces
These component categories are for components that specifically support the Visual Basic environment. Controls or containers that use these categories can support alternative methods. This capability is useful if a container encounters a control—or a control encounters a container—that does not support the Visual Basic private interface categories. The GUID for this component category is