home *** CD-ROM | disk | FTP | other *** search
/ Mastering MFC Development / MMD.ISO / samples / c12 / simpledual / simplectl.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-20  |  5.5 KB  |  218 lines

  1. // SimpleCtl.cpp : Implementation of the CSimpleCtrl ActiveX Control class.
  2.  
  3. #include "stdafx.h"
  4. #include "Simple.h"
  5. #include "SimpleCtl.h"
  6. #include "SimplePpg.h"
  7.  
  8.  
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14.  
  15.  
  16. IMPLEMENT_DYNCREATE(CSimpleCtrl, COleControl)
  17.  
  18.  
  19. /////////////////////////////////////////////////////////////////////////////
  20. // Message map
  21.  
  22. BEGIN_MESSAGE_MAP(CSimpleCtrl, COleControl)
  23.     //{{AFX_MSG_MAP(CSimpleCtrl)
  24.     //}}AFX_MSG_MAP
  25.     ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
  26. END_MESSAGE_MAP()
  27.  
  28.  
  29. /////////////////////////////////////////////////////////////////////////////
  30. // Dispatch map
  31.  
  32. BEGIN_DISPATCH_MAP(CSimpleCtrl, COleControl)
  33.     //{{AFX_DISPATCH_MAP(CSimpleCtrl)
  34.     DISP_PROPERTY_EX(CSimpleCtrl, "P1", GetP1, SetP1, VT_I4)
  35.     DISP_FUNCTION(CSimpleCtrl, "M1", M1, VT_EMPTY, VTS_NONE)
  36.     //}}AFX_DISPATCH_MAP
  37. END_DISPATCH_MAP()
  38.  
  39.  
  40. /////////////////////////////////////////////////////////////////////////////
  41. // Event map
  42.  
  43. BEGIN_EVENT_MAP(CSimpleCtrl, COleControl)
  44.     //{{AFX_EVENT_MAP(CSimpleCtrl)
  45.     EVENT_CUSTOM("E1", FireE1, VTS_NONE)
  46.     //}}AFX_EVENT_MAP
  47. END_EVENT_MAP()
  48.  
  49.  
  50. /////////////////////////////////////////////////////////////////////////////
  51. // Property pages
  52.  
  53. BEGIN_PROPPAGEIDS(CSimpleCtrl, 1)
  54.     PROPPAGEID(CSimplePropPage::guid)
  55. END_PROPPAGEIDS(CSimpleCtrl)
  56.  
  57.  
  58. /////////////////////////////////////////////////////////////////////////////
  59. // Initialize class factory and guid
  60.  
  61. IMPLEMENT_OLECREATE_EX(CSimpleCtrl, "SIMPLE.SimpleCtrl.1",
  62.     0xc48a81e3, 0x4384, 0x11d0, 0x9c, 0x9d, 0, 0, 0, 0, 0, 0)
  63.  
  64.  
  65. /////////////////////////////////////////////////////////////////////////////
  66. // Type library ID and version
  67.  
  68. IMPLEMENT_OLETYPELIB(CSimpleCtrl, _tlid, _wVerMajor, _wVerMinor)
  69.  
  70.  
  71. /////////////////////////////////////////////////////////////////////////////
  72. // Interface IDs
  73.  
  74. const IID BASED_CODE IID_DSimple =
  75.         { 0xc48a81e1, 0x4384, 0x11d0, { 0x9c, 0x9d, 0, 0, 0, 0, 0, 0 } };
  76. const IID BASED_CODE IID_DSimpleEvents =
  77.         { 0xc48a81e2, 0x4384, 0x11d0, { 0x9c, 0x9d, 0, 0, 0, 0, 0, 0 } };
  78.  
  79.  
  80. /////////////////////////////////////////////////////////////////////////////
  81. // Control type information
  82.  
  83. static const DWORD BASED_CODE _dwSimpleOleMisc =
  84.     OLEMISC_ACTIVATEWHENVISIBLE |
  85.     OLEMISC_SETCLIENTSITEFIRST |
  86.     OLEMISC_INSIDEOUT |
  87.     OLEMISC_CANTLINKINSIDE |
  88.     OLEMISC_RECOMPOSEONRESIZE;
  89.  
  90. IMPLEMENT_OLECTLTYPE(CSimpleCtrl, IDS_SIMPLE, _dwSimpleOleMisc)
  91.  
  92.  
  93. /////////////////////////////////////////////////////////////////////////////
  94. // CSimpleCtrl::CSimpleCtrlFactory::UpdateRegistry -
  95. // Adds or removes system registry entries for CSimpleCtrl
  96.  
  97. BOOL CSimpleCtrl::CSimpleCtrlFactory::UpdateRegistry(BOOL bRegister)
  98. {
  99.     // TODO: Verify that your control follows apartment-model threading rules.
  100.     // Refer to MFC TechNote 64 for more information.
  101.     // If your control does not conform to the apartment-model rules, then
  102.     // you must modify the code below, changing the 6th parameter from
  103.     // afxRegApartmentThreading to 0.
  104.  
  105.     if (bRegister)
  106.         return AfxOleRegisterControlClass(
  107.             AfxGetInstanceHandle(),
  108.             m_clsid,
  109.             m_lpszProgID,
  110.             IDS_SIMPLE,
  111.             IDB_SIMPLE,
  112.             afxRegApartmentThreading,
  113.             _dwSimpleOleMisc,
  114.             _tlid,
  115.             _wVerMajor,
  116.             _wVerMinor);
  117.     else
  118.         return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
  119. }
  120.  
  121.  
  122. /////////////////////////////////////////////////////////////////////////////
  123. // CSimpleCtrl::CSimpleCtrl - Constructor
  124.  
  125. CSimpleCtrl::CSimpleCtrl()
  126. {
  127.     InitializeIIDs(&IID_DSimple, &IID_DSimpleEvents);
  128. }
  129.  
  130.  
  131. /////////////////////////////////////////////////////////////////////////////
  132. // CSimpleCtrl::~CSimpleCtrl - Destructor
  133.  
  134. CSimpleCtrl::~CSimpleCtrl()
  135. {
  136. }
  137.  
  138.  
  139. /////////////////////////////////////////////////////////////////////////////
  140. // CSimpleCtrl::OnDraw - Drawing function
  141.  
  142. void CSimpleCtrl::OnDraw(
  143.             CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
  144. {
  145.     pdc->FillRect(rcBounds, CBrush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH)));
  146.     pdc->Ellipse(rcBounds);
  147. }
  148.  
  149.  
  150. /////////////////////////////////////////////////////////////////////////////
  151. // CSimpleCtrl::DoPropExchange - Persistence support
  152.  
  153. void CSimpleCtrl::DoPropExchange(CPropExchange* pPX)
  154. {
  155.     ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
  156.     COleControl::DoPropExchange(pPX);
  157.  
  158. }
  159.  
  160.  
  161. /////////////////////////////////////////////////////////////////////////////
  162. // CSimpleCtrl::OnResetState - Reset control to default state
  163.  
  164. void CSimpleCtrl::OnResetState()
  165. {
  166.     COleControl::OnResetState();  // Resets defaults found in DoPropExchange
  167. }
  168.  
  169.  
  170. /////////////////////////////////////////////////////////////////////////////
  171. // CSimpleCtrl message handlers
  172. void CSimpleCtrl::M1() 
  173. {
  174.     MessageBeep(-1);
  175. }
  176.  
  177. long CSimpleCtrl::GetP1() 
  178. {
  179.     return m_p1;
  180. }
  181.  
  182. void CSimpleCtrl::SetP1(long nNewValue) 
  183. {
  184.     m_p1 = nNewValue;
  185.     SetModifiedFlag();
  186. }
  187.  
  188. BEGIN_INTERFACE_MAP(CSimpleCtrl, COleControl)
  189.     INTERFACE_PART(CSimpleCtrl, DIID__DSimple, Dispatch )
  190.     INTERFACE_PART(CSimpleCtrl, IID__DSimpleDual, Nested )
  191. END_INTERFACE_MAP()
  192.  
  193. DELEGATE_DUAL_INTERFACE(CSimpleCtrl, Nested)
  194.  
  195. STDMETHODIMP CSimpleCtrl::XNested::put_P1(long newval)
  196. {
  197.     METHOD_PROLOGUE(CSimpleCtrl, Nested)
  198.  
  199.     pThis->SetP1(newval);
  200.     return NOERROR;
  201. }
  202.  
  203. STDMETHODIMP CSimpleCtrl::XNested::get_P1(long * retval)
  204. {
  205.        METHOD_PROLOGUE(CSimpleCtrl, Nested)
  206.     
  207.     *retval = pThis->GetP1();
  208.     return NOERROR;
  209. }
  210.  
  211. STDMETHODIMP CSimpleCtrl::XNested::M1()
  212. {
  213.        METHOD_PROLOGUE(CSimpleCtrl, Nested)
  214.     
  215.     pThis->M1();
  216.     return NOERROR;
  217. }
  218.