Property Pages for an ATL-Based Control

[Previous] [Next]

Unfortunately, the ATL COM AppWizard doesn't add a default property page to the DLL, which means that you need to do it yourself. Fortunately, there's a wizard for adding property pages to an ATL-based DLL. Just choose New ATL Object from the Insert menu and find the property page object. The wizard adds a dialog template and a C++ class with all the necessary COM goo to be a property page. It's your job to make this property page do something. The ATL property page, however, isn't quite as wizard driven as the MFC-based property page. You need to handle the apply and show operations by hand. This means providing implementations of functions named Apply and Show to your property page class. Usually the Apply function just extracts the state of the controls sitting on the dialog box and walks through the list of interface pointers to the control held by the property page, using the interface pointers to modify the control properties. The Show function usually extracts the state of your control and populates the dialog box controls. The following code shows how the ATL-based property page handles the Apply function:

 STDMETHOD(Apply)(void) {     long nInterval = GetDlgItemInt(IDC_EDITINTERVAL);     ATLTRACE(_T("CMainPropPage::Apply\n"));     for (UINT i = 0; i < m_nObjects; i++)     {         IATLMsgTrafficCtl* pATLMsgTrafficCtl;         m_ppUnk[i]->QueryInterface(IID_IATLMsgTrafficCtl,              (void**)&pATLMsgTrafficCtl);         if(pATLMsgTrafficCtl)          {             pATLMsgTrafficCtl->put_Interval(nInterval);             pATLMsgTrafficCtl->Release();         }     }     m_bDirty = FALSE;     return S_OK; } STDMETHOD(Show)( UINT nCmdShow ) {     if(nCmdShow == SW_SHOW ||         nCmdShow == SW_SHOWNORMAL)      {         for (UINT i = 0; i < m_nObjects; i++)          {             IATLMsgTrafficCtl* pATLMsgTrafficCtl;             m_ppUnk[i]->QueryInterface(IID_IATLMsgTrafficCtl,                  (void**)&pATLMsgTrafficCtl);             if(pATLMsgTrafficCtl)             {                 long nInterval;                 pATLMsgTrafficCtl->get_Interval(&nInterval);                 SetDlgItemInt(IDC_EDITINTERVAL, nInterval, FALSE);                 pATLMsgTrafficCtl->Release();             }         }     }     HRESULT hr = IPropertyPageImpl<CMainPropPage>::Show(nCmdShow);     return hr; } 

The second step in providing a property page to the ATL-based control is to make sure the class ID (CLSID) of the property page appears somewhere in the control's property map. Take another look at the code in section "Adding Properties" to see an example of this. The message map indicates that the standard color property page manages the control's graph line color and the control's main property page manages the control's sampling interval.



Inside Atl
Inside ATL (Programming Languages/C)
ISBN: 1572318589
EAN: 2147483647
Year: 1998
Pages: 127

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