CONTROLS: MFC-Based ActiveX Controls

An ActiveX control (formerly OLE control) is an ActiveX object with an extended interface that lets it behave like a control for Microsoft Windows®.

Adding ActiveX Controls to the Dialog Editor

To place ActiveX controls or objects on the dialog editor Controls toolbar, you must first add ActiveX controls to your project in the Component Gallery. Once inserted, the ActiveX controls appear on the dialog editor Controls toolbar and can be dragged to the dialog box that you are constructing. The controls that you apply are reloaded each time you start the project.

To add an ActiveX control to the project

  1. On the Project menu, choose Add To Project, then choose Components and Controls. The Gallery dialog box appears.

  2. Choose the Registered ActiveX Controls folder.

  3. Select the control you want by clicking an ActiveX control icon.

  4. Click Insert.

An icon representing each installed control appears on the dialog editor Controls toolbar.

Manual Registration of ActiveX Controls

For the following procedure to work, the ActiveX development tools must be installed and the development environment must be open.

  1. On the Tools menu, click Test Container.
    The Test Container application will start up.

  2. On the Tools menu, click Register Controls.
    The Controls Registry dialog box appears.

  3. Click Register.
    The Register Controls dialog box appears.

  4. Select the directory in which the ActiveX control is installed.

  5. In the File Name list, double-click the file of the control.
    Test Container will register the control and add it to the list in the Controls Registry box.

  6. Click Close to close Controls Registry.
    You can now insert your control in Test Container or in any dialog or form you want.

The following samples demonstrate ActiveX Controls:

Click to open or copy the BUTTON project files.

BUTTON: A control subclassed from a Windows button control. Demonstrates use of an in-place active menu, a stock property page, and the About box control option.

Click to open or copy the CIRC1 project files.

CIRC1: The Circle control just after it is created with ControlWizard.

Click to open or copy the CIRC2 project files.

CIRC2: The Circle control after several properties and events have been added.

Click to open or copy the CIRC3 project files.

CIRC3: The completed Circle control. Demonstrates ActiveX control basics, including control painting, stock and custom properties, stock and custom events, use of colors and fonts, the stock Font property page, the default property page, and versioning.

Click to open or copy the DB project files.

DB: A control that illustrates use of the CRecordSet and CDatabase classes.

Click to open or copy the LICENSED project files.

LICENSED: A control that enforces use of a design-time and run-time license.

Click to open or copy the LOCALIZE project files.

LOCALIZE: A control with a localized user interface. Demonstrates use of separate type libraries and resource dynamic-link libraries (DLLs) for localization.

Click to open or copy the PAL project files.

PAL: A control that displays the colors of a palette. Demonstrates read-only properties, persistent Get/Set properties, persistent parameterized properties, and picture properties.

Click to open or copy the PUSH project files.

PUSH: A control subclassed from a Windows owner-drawn button control. Demonstrates stock properties, custom events, and picture holders.

Click to open or copy the REGSVR project files.

REGSVR: This utility is used to invoke the self-registration code built into ActiveX Controls to add or remove a control's information in the registry.

Click to open or copy the SPINDIAL project files.

SPINDIAL: A control with the visual appearance of a spin-dial. Demonstrates property page data validation.

Click to open or copy the TIME project files.

TIME: A control that is invisible at run time and fires a timer event at set intervals. Demonstrates notification functions and ambient properties.

Click to open or copy the XLIST project files.

XLIST: A control, subclassed from a Windows list box, that displays text or bitmap items. Demonstrates methods, ambient properties, picture holders, and font holders.

The BUTTON sample demonstrates the following keywords:

AfxGetInstanceHandle; CDialog::DoModal; CMenu::LoadMenu; HIWORD; MAKELONG

The CIRC1 sample demonstrates the following keywords:

AfxGetInstanceHandle; CDialog::DoModal; Ellipse; FillRect; GetStockObject; MAKELONG

The CIRC2 sample demonstrates the following keywords:

AfxGetInstanceHandle; CDC::Ellipse; CDC::SelectObject; CDC::SelectStockObject; CDialog::DoModal; Ellipse; FillRect; GetClientRect; GetDC; MAKELONG; RGB; ReleaseDC; SelectObject

The CIRC3 sample demonstrates the following keywords:

AfxGetInstanceHandle; CDC::Ellipse; CDC::SelectObject; CDC::SelectStockObject; CDialog::DoModal; CString::AllocSysString; CString::GetLength; Ellipse; ExtTextOut; FillRect; GetClientRect; GetDC; GetVersion; MAKELONG; RGB; ReleaseDC; SelectObject; SetBkMode; SetTextAlign; SetTextColor

The DB sample demonstrates the following keywords:

AfxGetInstanceHandle; CComboBox::AddString; CComboBox::GetCount; CComboBox::GetCurSel; CComboBox::GetLBText; CComboBox::ResetContent; CComboBox::SelectString; CDialog::DoModal; CFieldExchange::SetFieldType; CRecordset::DoFieldExchange; CString::Empty; CString::IsEmpty; CWnd::EnableWindow; EnableWindow; GetDlgItem; HIWORD; MAKELONG; MessageBox; SendMessage; lstrlen; strcat; strchr; strcpy; strlen; strstr; wsprintf

The LICENSED sample demonstrates the following keywords:

AfxGetInstanceHandle; CDC::ExtTextOut; CDC::SelectObject; CDC::SetTextAlign; CDialog::DoModal; CString::GetLength; MAKELONG; MessageBox

The LOCALIZE sample demonstrates the following keywords:

AfxGetInstanceHandle; AfxGetResourceHandle; AfxSetResourceHandle; CDC::InvertRect; CDialog::DoModal; CString::GetLength; CString::LoadString; ExtTextOut; FreeLibrary; GetClientRect; GetDC; LibMain; LoadLibrary; MAKELONG; ReleaseCapture; ReleaseDC; SelectObject; SetCapture; SetTextAlign

The PAL sample demonstrates the following keywords:

AfxGetInstanceHandle; CBrush::CreateSolidBrush; CDC::IntersectClipRect; CDC::PatBlt; CDC::RealizePalette; CDC::SelectObject; CDC::SelectPalette; CDialog::DoModal; CGdiObject::Attach; CGdiObject::CreateStockObject; CGdiObject::Detach; CGdiObject::GetObject; CGdiObject::UnrealizeObject; COleDispatchDriver::AttachDispatch; COleDispatchDriver::GetProperty; CPalette::GetPaletteEntries; CRect::Height; CRect::Width; CreateBitmap; CreatePalette; GetBValue; GetDC; GetDeviceCaps; GetGValue; GetObject; GetPaletteEntries; GetRValue; GetStockObject; GlobalAlloc; GlobalFree; GlobalLock; MAKELONG; PALETTEINDEX; RGB; ReleaseDC; ResizePalette; SetPaletteEntries

The PUSH sample demonstrates the following keywords:

AfxGetInstanceHandle; CBitmap::LoadBitmap; CDC::DrawFocusRect; CDC::SelectObject; CDC::SelectStockObject; CDialog::DoModal; CGdiObject::GetObject; CString::GetLength; CopyRect; HIWORD; InflateRect; MAKELONG; min

The REGSVR sample demonstrates the following keywords:

FreeLibrary; GetLastError; GetProcAddress; LoadLibrary; LoadString; MessageBox; OleInitialize; OleUninitialize; WinMain; lstrcpy; lstrlen; wsprintf

The SPINDIAL sample demonstrates the following keywords:

AfxGetInstanceHandle; CBrush::CreateSolidBrush; CDC::Ellipse; CDC::FillRect; CDC::LineTo; CDC::MoveTo; CDC::SelectObject; CDC::SelectStockObject; CDialog::DoModal; MAKELONG

The TIME sample demonstrates the following keywords:

AfxGetInstanceHandle; CBitmap::LoadBitmap; CDialog::DoModal; CGdiObject::GetObject; KillTimer; MAKELONG; SetTimer

The XLIST sample demonstrates the following keywords:

AddItem; AfxGetInstanceHandle; CBrush::CreateSolidBrush; CDC::DrawFocusRect; CDC::ExtTextOut; CDC::FillRect; CDC::InvertRect; CDC::SelectObject; CDC::SelectStockObject; CDC::SetBkMode; CDC::SetTextColor; CDialog::DoModal; CObArray::GetAt; CObArray::GetSize; CObArray::InsertAt; CObArray::RemoveAll; CObject::IsKindOf; COleDispatchDriver::AttachDispatch; COleDispatchDriver::DetachDispatch; COleDispatchDriver::GetProperty; CString::AllocSysString; GetDC; GetDeviceCaps; GetSystemMetrics; HIWORD; LOWORD; MAKELONG; ReleaseDC; SendMessage