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

  1. // CircProps.h : Declaration of the CCircProps
  2. //
  3. // This is a part of the Active Template Library.
  4. // Copyright (C) 1996-1998 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Active Template Library Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Active Template Library product.
  12.  
  13. #include "resource.h"       // main symbols
  14. #include <atlwin.h>
  15. #include <atlctl.h>
  16. #include "circprres.h"
  17. #include "circ.h"
  18.  
  19. #define IID_DEFINED
  20. #include "circ_i.c"
  21.  
  22.  
  23. extern const GUID CLSID_CCircProps;
  24.  
  25. template <class T>
  26. class CCircPropertyPageDlg :
  27.     public IPropertyPageImpl<T>,
  28.     public CDialogImpl<T>
  29.     {
  30. public:
  31.     typedef CCircPropertyPageDlg className;
  32.  
  33.     CCircPropertyPageDlg()
  34.     {
  35.         lstrcpy(m_szTitle, _T("OldMotherHubbard"));
  36.     }
  37.  
  38.     enum {IDD = IDD_CIRCPROPS};
  39.  
  40.     BEGIN_MSG_MAP(CCircPropertyPageDlg< T >)
  41.         COMMAND_ID_HANDLER(IDC_SETTEXT, OnSetText)
  42.         MESSAGE_HANDLER(WM_CTLCOLOREDIT, OnCtlColorEdit)
  43.         CHAIN_MSG_MAP(IPropertyPageImpl<T>)
  44.     END_MSG_MAP()
  45.  
  46.     TCHAR m_szTitle[_MAX_PATH];
  47.  
  48.     LRESULT OnSetText(WORD wNotify, WORD wID, HWND hWnd, BOOL& bHandled)
  49.     {
  50.         SendDlgItemMessage(IDC_EDIT1, EM_GETLINE, 0, (LPARAM)m_szTitle);
  51.         SetDirty(TRUE);
  52.         return 0;
  53.     }
  54.     LRESULT OnCtlColorEdit(UINT, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  55.     {
  56.         ::SetTextColor((HDC)wParam, RGB(255,255,0));
  57.         ::SetBkMode((HDC)wParam, TRANSPARENT);
  58.         return (LRESULT)::GetStockObject(BLACK_BRUSH);
  59.     }
  60.     LRESULT OnPagePropMsg(UINT, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  61.     {
  62.         ATLTRACE(_T("Recieved  Page Prop Message\n"));
  63.         return 0;
  64.     }
  65. };
  66.  
  67. /////////////////////////////////////////////////////////////////////////////
  68. // circ
  69.  
  70. class CCircProps :
  71.     public CComObjectRoot,
  72.     public CComCoClass<CCircProps,&CLSID_CCircProps>,
  73.     public CCircPropertyPageDlg<CCircProps>
  74. {
  75.  
  76. public:
  77.     CCircProps()
  78.     {
  79.         m_dwTitleID = IDS_TITLE;
  80.         m_dwHelpFileID = IDS_HELPFILE;
  81.         m_dwDocStringID = IDS_DOCSTRING;
  82.     }
  83.     STDMETHOD(Apply)(void)
  84.     {
  85.         ICircCtl* pCirc;
  86.  
  87.         ATLTRACE(_T("CCircProps::Apply\n"));
  88.         for (UINT i = 0; i < m_nObjects; i++)
  89.         {
  90.             m_ppUnk[i]->QueryInterface(IID_ICircCtl, (void**)&pCirc);
  91.             pCirc->put_Caption(CComBSTR(m_szTitle));
  92.             pCirc->Release();
  93.         }
  94.         m_bDirty = FALSE;
  95.         return S_OK;
  96.     }
  97.     STDMETHOD(GetPageInfo)(PROPPAGEINFO *pPageInfo)
  98.     {
  99.         ATLTRACE(_T("CCircProps::GetPageInfo\n"));
  100.         LONG cDlgBaseUnits = GetDialogBaseUnits();
  101.  
  102.         m_size.cx = (LOWORD(cDlgBaseUnits) * 188) / 4;
  103.         m_size.cy = (HIWORD(cDlgBaseUnits) * 97) / 8;
  104.  
  105.         return CCircPropertyPageDlg<CCircProps>::GetPageInfo(pPageInfo);
  106.     }
  107.  
  108.     STDMETHOD(SetObjects)(ULONG nObjects, IUnknown **ppUnk)
  109.     {
  110.         HRESULT hr = IPropertyPageImpl<CCircProps>::SetObjects(nObjects, ppUnk);
  111.         if (SUCCEEDED(hr))
  112.         {
  113.             CComPtr<ICircCtl> pCirc;
  114.             m_ppUnk[0]->QueryInterface(IID_ICircCtl, (void**)&pCirc);
  115.             if (pCirc != NULL)
  116.             {
  117.                 USES_CONVERSION;
  118.                 BSTR bstrTitle;
  119.                 pCirc->get_Caption(&bstrTitle);
  120.                 lstrcpy(m_szTitle, OLE2T(bstrTitle));
  121.             }
  122.         }
  123.         return hr;
  124.     }
  125.  
  126. BEGIN_COM_MAP(CCircProps)
  127.     COM_INTERFACE_ENTRY_IMPL(IPropertyPage)
  128. END_COM_MAP()
  129.  
  130. DECLARE_GET_CONTROLLING_UNKNOWN()
  131. DECLARE_REGISTRY_RESOURCEID(IDR_CircProps)
  132. };
  133.