This documentation is archived and is not being maintained.

How to: Host an ActiveX Control in a Dialog Resource 

When you use Visual Studio 2005 to design ActiveX controls for devices, you need to add a few extra steps. Because the Resource Editor relies on the control being registered on the desktop computer to manipulate it at design time and because you cannot register device controls on the desktop computer, the following steps provide an alternative design time experience. The following procedures assume you already have your ActiveX control project and host project, and you are hosting the ActiveX control in a dialog box.


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.

To add ActiveX controls by using the Dialog editor

  1. In the Dialog editor, open the dialog box of the host project.

  2. From the Toolbox, drag a custom control onto the dialog box.

  3. Position and size the custom control on the dialog box to reflect how you want your ActiveX control to appear.

  4. Right-click the custom control, and then click Properties.

  5. In the Class property, paste the GUID of the ActiveX control. Remember to include the curly braces "{…}".

  6. In Solution Explorer, right-click the Project Name.RC2 file, and then click View Code.

  7. In the Add manually edited resources here section, add the following code. The custom control requires a dialog init section to display correctly. The contents of the actual dialog init section are not used. Remember to replace <project name> with the name of your project.

    IDD_<project name>_DIALOG DLGINIT BEGIN IDC_CUSTOM1, 0x376, 22, 0 0x0000, 0x0000, 0x0800, 0x0000, 0x094d, 0x0000, 0x043d, 0x0000, 0x0013, 0xcdcd, 0xcdcd, 0
  8. Build and run your host project. Remember to deploy and register the ActiveX control on the target device.

To use an alternative method for hosting ActiveX Controls

  1. Register the AtlAxWin80 window class by calling AtlAxWinInit at some point in the application. ATL applications do this in the module initialization code. Win32 applications should call this function in the WinMain function. For MFC applications, follow these steps:

    1. Right-click the project node in Solution Explorer and click Add and then click Class.

    2. Click Add ATL support to MFC (under the Smart Device heading).

    3. Add the AtlAxWinInit call to the top of the InitInstance method of the host application class.

  2. In a dialog resource (such as an ATL dialog or composite control, or MFC dialog):

    1. Drag a custom control from the Toolbox.

    2. Set the window class property to AtlAxWin80.

    3. Set the caption to the GUID in curly braces, or the progid.

  3. For MFC, add atl.lib as additional link input.

  4. For MFC, add these lines to the Deployment | Additional Files option. The lines will already be there for dynamic link libraries, but need to be added for MFC statically linked libraries.


See Also