Walkthrough: Creating an MFC Multiplatform ActiveX Control for Smart Devices
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.

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.

NoteNote:

Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. The Visual Studio edition that you have and the settings that you use determine these elements. 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 Visual C++ 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 start 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 want 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.

    NoteNote:

    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 have to include the following DLLs in the Additional Files property of the newly added platform: Mfc90u.dll, Atl90.dll, Msvcr90.dll. This example assumes a retail configuration.

To add code to the OnDraw method of MFC ActiveX control

  1. In Solution Explorer, expand Source Files, 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)
            return;
     
        CRect rect;
        GetClientRect(&rect);
        pdc->DrawTextW(_T("Hello World"),11, &rect,1);
    }
    
  3. On the Build menu, click Rebuild 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.

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, expand Device Tools, and then click General. If you cannot see Device Tools, 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.

Show:
© 2016 Microsoft