Freigeben über


How Do I Load Controls Specified at Run Time?

To load controls dynamically, you need to create an "AtlAxWin80" hosting window and specify the control that it should host. There are two main ways of doing this:

  1. Use the standard window creation API and the ATL hosting API. This technique is described in the Knowledge Base article "Adding ATL Control Containment Support to Any Window" (Q192560). You can find Knowledge Base articles in the MSDN Library or at https://support.microsoft.com.

  2. Use the CAxWindow class as described below:

    • Make sure that AtlAxWinInit has been called.

      AtlAxWinInit();
      

      AtlAxWinInit initializes the control-hosting code.

    • Create a CAxWindow object:

      CAxWindow wnd;
      

      CAxWindow is a CWindow-derived wrapper for creating and manipulating "AtlAxWin80" windows.

    • Create a host window and control by calling Create.

      RECT rect = { 0, 0, 100, 100 };
      wnd.Create(m_hWnd, rect, _T("MSCAL.Calendar"), WS_CHILD | WS_VISIBLE | 
         WS_CLIPSIBLINGS | WS_CLIPCHILDREN, WS_EX_CLIENTEDGE);
      

      The window title (the third parameter) passed to the Create function is a string identifying the control to create. This string can be a CLSID (with braces), a ProgID, a URL, or raw HTML (prefixed with MSHTML:). If either a URL or raw HTML is supplied, the Web browser will be loaded with this information.

For information on control lifetimes, see How Do I Destroy a Control?.

See Also

Concepts

ATL Control Containment FAQ