HOWTO: Adding ATL Control Containment Support to Any WindowID: Q192560
|
This article lists the steps needed to add ATL's generic control containment capability to any window, so that the window can host ActiveX controls. The control containment support conforms to the OCX 96 specification and supports windowless activation and flicker-free drawing.
Steps for adding control containment:
// AtlAxWinInit is implemented in Atl.dll
#pragma comment(lib, "atl.lib")
#include <atldef.h>
#define _ATL_DLL_IMPL
#include <atliface.h>
If you do not want to redistribute Atl.dll and want to link in the
containment code statically, add the following.
// link in AltAxWinInit() & containment code statically
// this require a instance (_Module) of CComModule
#include <atlbase.h>
extern CComModule _Module;
#include <atlcom.h>
#include <atlhost.h>
CComModule _Module;
// The following line is needed only for static linkage.
//hInstance is module handle returned by ::GetModuleHandle(NULL)
_Module.Init(NULL, hInstance);
//Initialize ATL control containment code.
AtlAxWinInit();
// Create the Calendar control specifying the ProgID.
// Make sure the module handle you pass to CreateWindow is the same
// module handle where AtlAxWinInit() was called from.
HWND hWnd = ::CreateWindow("AtlAxWin", "MSCAL.Calendar",
WS_CHILD|WS_VISIBLE, 10, 10, 500, 300, hParent, NULL,
::GetModuleHandle(NULL), NULL);
// Same as above except CLSID is specified instead of ProgID
// corresponds to ProgID "MSCAL.Calendar.7"
HWND hWnd = ::CreateWindow("AtlAxWin",
"{8E27C92B-1264-101C-8A2F-040224009C02}",
WS_CHILD|WS_VISIBLE, 10, 10, 500, 300, hParent, NULL,
::GetModuleHandle(NULL), NULL);
// Creates the Web Browser control & navigates to specified web page.
HWND hWnd = ::CreateWindow("AtlAxWin", "<LINK TYPE="GENERIC" VALUE="http://www.microsoft.com",">http://www.microsoft.com",</LINK>
WS_CHILD|WS_VISIBLE, 10, 10, 500, 300, hParent, NULL,
::GetModuleHandle(NULL), NULL);
// Creates an instance of an dynamic HTML document.
HWND hWnd = ::CreateWindow("AtlAxWin", "mshtml:<H1>Hello World</H1>",
WS_CHILD|WS_VISIBLE, 10, 10, 500, 300, hParent, NULL,
::GetModuleHandle(NULL), NULL);
_Module.Term()
(c) Microsoft Corporation 1998, All Rights Reserved. Contributions by Jaganathan Thangavelu, Microsoft Corporation.
Additional query words:
Keywords : kbActiveX kbATL kbATLWC kbCOMt kbCtrl kbVC600 kbATL300 kbATL300faq
Version : WINDOWS:3.0
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: April 30, 1999