Introduced
In the sixth chapter, I'll introduce ATL's support for using ActiveX controls in dialog boxes, because ActiveX controls are the specialty of ATL, so WTL doesn't add other helper classes. However, using ActiveX controls in ATL is very different from MFC, so you need to focus on this. I'll explain how to containment a control and handle the control's events, and it's a little inconvenient to develop an ATL application's Class Wizard relative to MFC. ATL's support for containment ActiveX controls can naturally be used in WTL programs.
Example project demonstrates how to use IE's browser controls, and I have two advantages in choosing a Browser Control:
- Each computer has this control, and
- It has a lot of methods and events and is a good example of how to do the demo.
I certainly can't compare to people who spend a lot of time writing custom browsers based on IE browser Controls, but when you finish reading this article, you know how to start writing your own custom browsers!
To create a project from using the wizard
WTL Wizards can create a program that supports containment ActiveX controls, and I'll start a new project called Iehoster. We used the modeless dialog as we did in the previous chapter, but this time we're going to choose to support ActiveX containment (Enable ActiveX control Hosting), as shown in the following figure:
Selecting this check box will enable our dialog box to derive from CAxDialogImpl so that ActiveX controls can be contained. On the second page of the wizard There is also a check box called Containment ActiveX control, but choosing this seems to have no effect on the final result, so you can click Finish to finish the wizard on the first page.
Wizard-Generated code
In this section I'll introduce some new code (generated by the wizard) that I haven't seen before, and the next section describes the details of the ActiveX containment class.
The first file to look at is stdafx.h, which contains the files:
#include <atlbase.h>
#include <atlapp.h>
extern CAppModule _Module;
#include <atlcom.h>
#include <atlhost.h>
#include <atlwin.h>
#include <atlctl.h>
// .. other WTL headers ...