COM Controls


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      CLASS     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."

Figure 1.16. The CalcPi control hosted in Internet Explorer





ATL Internals. Working with ATL 8
ATL Internals: Working with ATL 8 (2nd Edition)
ISBN: 0321159624
EAN: 2147483647
Year: 2004
Pages: 172

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net