TESTHELP Sample: ActiveX Control with Tooltips and Help

The TESTHELP sample demonstrates how to use MFC to build an ActiveX control that has its own help file to display help for the user. Testhelp.ocx also shows how to add tooltips to an MFC ActiveX control.

Security noteSecurity Note

This sample code is intended to illustrate a concept, and it shows only the code that is relevant to that concept. It may not meet the security requirements for a specific environment, and it should not be used exactly as shown. We recommend that you add security and error-handling code to make your projects more secure and robust. Microsoft provides this sample code "AS IS" with no warranties.

To get samples and instructions for installing them:

To access samples from Visual Studio

  • On the Help menu, click Samples.

    By default, these samples are installed in drive:\Program Files\Microsoft Visual Studio 10.0\Samples\.

  • For the most recent version of this sample and a list of other samples, see Visual Studio Samples on the MSDN Web site.

Building and Running the Sample

To build and run the TESTHELP sample

  1. Open the solution Testhelp.sln.

  2. On the Build menu, click Build.

After you have built the TESTHELP sample, you will be able to use it in any ActiveX container application. See Testing Properties and Events with Test Container for information on how to access the test container. Include the TESTHELP control in your container's project and run the project. You can set the properties of the TESTHELP control by opening the property dialog of your container.

The Help project file and all Help project's source files are also included in this sample.

To rebuild and run the TESTHELP help file

  1. From the Start menu, click Help Workshop.

  2. Open Testhelp.hpj. Help Workshop displays a wizard to convert the file into an .hhp file. Run the wizard, naming the file and accepting the changes.

  3. Click Compile on the File menu. In the Create a compiled file dialog box, indicate where you want to store the compiled file, and then click Compile.

  4. To view the compiled file, click Compiled Help Fileon the View menu.

TESTHELP Features

TESTHELP demonstrates how to:

  • Display a tooltip for your ActiveX control.

  • Toggle the tooltip on and off using the control's property page.

  • Change the tooltip's text using the control's property page.

  • Enable the ActiveX control container's property frame Help button to display the control's help file when the Help button is clicked.

  • Enable the "?" button in Visual C++'s Component and Controls Gallery so that the control's help file will be displayed when this control is chosen from the Gallery and the "?" button is clicked.

  • Display help at run time when the control has the keyboard focus and F1 is pressed.

  • Use the Font, BackColor, and ForeColor stock properties of an ActiveX control.

General Property Page

  • Type of Help to Use
    This property determines how help will be used when the user presses F1 while the TESTHELP control has the keyboard focus. Help in a pop-up window means that when the user presses F1 while the TESTHELP control is running in a container and has the keyboard focus, a pop-up window with the "What is this thing?" topic from the Testhelp.hlp helpfile is displayed. Show the Whole Help File means that when the user presses F1 while the TESTHELP control is running in a container and has the keyboard focus, the entire Windows help program will come up displaying the contents topic of the Testhelp.hlp file.

  • Use Control's Help File
    When this box is checked, help will be displayed in the format determined by the Type of Help to Use property when the user presses F1 while the control is running in a container and has the keyboard focus.

  • Use ToolTip for this Control
    If this box is checked, a tooltip will be displayed over the control's window if the control is running in the container and the mouse cursor moves into and stops in the control's window. The text to be displayed is determined by the Tooltip Caption property.

  • Tooltip Caption
    This is the text to be displayed in a tooltip if the user chooses to show tooltips.

    • Name1   The name displayed at the top of the control.

    • Name2   The name displayed in the middle of the control.

    • Name3   The name displayed at the bottom of the control.

Color Property Page

Lets the user select colors to be used in painting this control.

Font Property Page

Lets the user specify the font used for the text on the control.

Note

Some samples, such as this one, have not been modified to reflect the changes in the Visual C++ wizards, libraries, and compiler, but still demonstrate how to complete your desired task.

Keywords

The TESTHELP sample demonstrates the following classes and keywords:

CToolTipCtrl; COleControl::OnDraw; COleControl::OnResetState; COlePropertyPage::OnHelp

Note

Some samples, such as this one, have not been modified to reflect the changes in the Visual C++ wizards, libraries, and compiler, but still demonstrate how to complete your desired task.

See Also

Other Resources

MFC Samples