home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / atl / polygon / polyprop.h < prev    next >
C/C++ Source or Header  |  1998-03-26  |  2KB  |  74 lines

  1. // PolyProp.h : Declaration of the CPolyProp
  2.  
  3. #ifndef __POLYPROP_H_
  4. #define __POLYPROP_H_
  5.  
  6. #include "Polygon.h"        // definition of IPolyCtl
  7. #include "resource.h"       // main symbols
  8.  
  9. EXTERN_C const CLSID CLSID_PolyProp;
  10.  
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CPolyProp
  13. class ATL_NO_VTABLE CPolyProp :
  14.     public CComObjectRootEx<CComSingleThreadModel>,
  15.     public CComCoClass<CPolyProp, &CLSID_PolyProp>,
  16.     public IPropertyPageImpl<CPolyProp>,
  17.     public CDialogImpl<CPolyProp>
  18. {
  19. public:
  20.     CPolyProp()
  21.     {
  22.         m_dwTitleID = IDS_TITLEPolyProp;
  23.         m_dwHelpFileID = IDS_HELPFILEPolyProp;
  24.         m_dwDocStringID = IDS_DOCSTRINGPolyProp;
  25.     }
  26.  
  27.     enum {IDD = IDD_POLYPROP};
  28.  
  29. DECLARE_REGISTRY_RESOURCEID(IDR_POLYPROP)
  30.  
  31. BEGIN_COM_MAP(CPolyProp)
  32.     COM_INTERFACE_ENTRY(IPropertyPage)
  33. END_COM_MAP()
  34.  
  35. BEGIN_MSG_MAP(CPolyProp)
  36.     COMMAND_HANDLER(IDC_SIDES, EN_CHANGE, OnChangeSides)
  37.     CHAIN_MSG_MAP(IPropertyPageImpl<CPolyProp>)
  38. END_MSG_MAP()
  39. // Handler prototypes:
  40. //  LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  41. //  LRESULT CommandHandler(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
  42. //  LRESULT NotifyHandler(int idCtrl, LPNMHDR pnmh, BOOL& bHandled);
  43.  
  44. STDMETHOD(Apply)(void)
  45. {
  46.     USES_CONVERSION;
  47.     ATLTRACE(_T("CPolyProp::Apply\n"));
  48.  
  49.     for (UINT i = 0; i < m_nObjects; i++)
  50.     {
  51.         CComQIPtr<IPolyCtl, &IID_IPolyCtl> pPoly(m_ppUnk[i]);
  52.         short nSides = (short)GetDlgItemInt(IDC_SIDES);
  53.         if FAILED(pPoly->put_Sides(nSides))
  54.         {
  55.             CComPtr<IErrorInfo> pError;
  56.             CComBSTR         strError;
  57.             GetErrorInfo(0, &pError);
  58.             pError->GetDescription(&strError);
  59.             MessageBox(OLE2T(strError), _T("Error"), MB_ICONEXCLAMATION);
  60.             return E_FAIL;
  61.             }
  62.     }
  63.     m_bDirty = FALSE;
  64.     return S_OK;
  65. }
  66.     LRESULT OnChangeSides(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  67.     {
  68.         SetDirty(TRUE);
  69.         return 0;
  70.     }
  71. };
  72.  
  73. #endif //__POLYPROP_H_
  74.