COM controls are objects that provide their own
user interface (UI), which is closely integrated with that of their
container. ATL provides extensive support for COM controls via the
CComControl base class, as well as various other base
IXxxImpl classes. These base classes handle most of the
details of being a basic control (although there's plenty of room
for advanced features, as shown in Chapter 11, "ActiveX Controls"). Had you
chosen ATL Control from the Add Class dialog box when generating
the CalcPi class, you could have provided the UI merely by
implementing the OnDraw function:
HRESULT CCalcPi::OnDraw(ATL_DRAWINFO& di) {
CComBSTR bstrPi;
if( SUCCEEDED(this->CalcPi(&bstrPi)) ) {
DrawText(di.hdcDraw, COLE2CT(bstrPi), -1,
(RECT*)di.prcBounds,
DT_SINGLELINE | DT_CENTER | DT_VCENTER);
}
return S_OK;
}
The wizard would also have generated a sample
HTML page, which I've augmented to take up the entire browser
window and to set the initial number of digits to 50:
<HTML>
<HEAD>
<TITLE>ATL 8.0 test page for object CalcPiControl</TITLE>
</HEAD>
<BODY>
<OBJECT ID="CalcPi"
CLASSID="CLSID:9E7ABA7A-C106-4813-A50C-B15C967264B6"
height="100%" width="100%">
<param name="Digits" value="50">
</OBJECT>
</BODY>
</HTML>
Displaying this sample page in Internet Explorer
yields a view of a control (see Figure 1.16). For more information about building
controls in ATL, see Chapter 11, "ActiveX Controls."