This documentation is archived and is not being maintained.

Walkthrough: Creating an MFC Multiplatform ActiveX Control for Smart Devices 

You can use Visual C++ to write MFC ActiveX control code targeting multiple devices. This walkthrough illustrates how to build a C++ multiplatform MFC ActiveX control for use with multiple devices.

Create an MFC ActiveX Multiplatform Control Project

This walkthrough consists of three main tasks:

  • Creating a multiplatform smart device MFC ActiveX control project.

  • Adding code to the OnDraw() method of MFC ActiveX control.

  • Deploying the Multiplatform MFC ActiveX control solution for testing.

For more information, see MFC Smart Device ActiveX Control Wizard.


The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Visual Studio Settings.

This walkthrough was written using Visual C++ Development Settings.

To create a Multiplatform Smart Device MFC ActiveX control project

  1. On the File menu, point to New, click Project, expand the Visual C++ node in the Project Types pane, and then click Smart Device.

  2. In the Templates pane, click MFC Smart Device ActiveX Control.

  3. In the Name box, type MFCAX.

  4. In the Solution box, accept the default option Create directory for solution.

  5. Click OK to launch the MFC Smart Device ActiveX Control Wizard.

  6. Click Next on the MFC Smart Device Application Wizard Welcome page. The Platforms, MFC Smart Device ActiveX Control Wizard appears, and you can select the platform or platforms to be added to the current project.

    From the Installed SDKs pane, select the platforms you would like to target and add to the current project, such as Smartphone 2003 and Pocket PC 2003. To add a platform, select the platform in the left pane, such as Smartphone 2003, and click the button with the right arrow (>) on it. To remove a platform, select the platform in the right pane, such as Pocket PC 2003, and click the button with the left arrow (<) on it.

  7. Click Finish to complete and close the wizard, or click Next to accept the defaults for all the remaining options in the wizard.


    Having created a device project, you can always add more platforms, after the initial creation. However, adding a new platform to an existing project does not add the additional dependent runtime DLLs to the Additional Files config property. For example, if your application dynamically links to MFC, you will need to include the following DLLs in the Additional Files property of the newly added platform: Mfc80u.dll, Atl80.dll, Msvcr80.dll. This example assumes a retail configuration.

Add Code to the OnDraw() Method of the Multiplatform MFC Control

To add code to the OnDraw method of MFC ActiveX control

  1. In Solution Explorer, expand the Source Files node, and select and open the MFCAXCtrl.cpp source file in the editor.

  2. Replace the code for the OnDraw method with the following code, specifically the last three lines:

    void CMFCAXCtrl::OnDraw(
        CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
        if (!pdc)
        CRect rect;
        pdc->DrawTextW(_T("Hello World"),11, &rect,1);
  3. On the Build menu, click Rebuild Solution.

Deploy the Multiplatform Solution

To deploy the solution

  1. In order to run the deployed solution, on the target device, deploy and register the ActiveX control project first.

  2. On the Target Device drop-down list on the Visual Studio toolbar, select your target, for example, Pocket PC 2003 SE Emulator or Pocket PC 2003 Device.

  3. On the Build menu, click Deploy.

Choosing a Target Device

To ensure that you are prompted to select a device when you deploy your solution, complete the following procedure.

To prompt for device choices at deployment time

  1. On the Tools menu, click Options, click Device Tools, and then click General. If Device Tools is not visible, select Show all settings at the bottom of the Options dialog box.

  2. Select the Show device choices before deploying a device project check box.

For more information, visit the Mobile Developer Center.

See Also