home *** CD-ROM | disk | FTP | other *** search
/ Using Visual C++ 4 (Special Edition) / Using_Visual_C_4_Special_Edition_QUE_1996.iso / ch10 / cal2code / cal2ctl.cpp next >
Encoding:
C/C++ Source or Header  |  1995-11-01  |  6.2 KB  |  224 lines

  1. // Cal2Ctl.cpp : Implementation of the CCal2Ctrl OLE control class.
  2.  
  3. #include "stdafx.h"
  4. #include "Cal2.h"
  5. #include "Cal2Ctl.h"
  6. #include "Cal2Ppg.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(CCal2Ctrl, COleControl)
  17.  
  18.  
  19. /////////////////////////////////////////////////////////////////////////////
  20. // Message map
  21.  
  22. BEGIN_MESSAGE_MAP(CCal2Ctrl, COleControl)
  23.     //{{AFX_MSG_MAP(CCal2Ctrl)
  24.     // NOTE - ClassWizard will add and remove message map entries
  25.     //    DO NOT EDIT what you see in these blocks of generated code !
  26.     //}}AFX_MSG_MAP
  27.     ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
  28. END_MESSAGE_MAP()
  29.  
  30.  
  31. /////////////////////////////////////////////////////////////////////////////
  32. // Dispatch map
  33.  
  34. BEGIN_DISPATCH_MAP(CCal2Ctrl, COleControl)
  35.     //{{AFX_DISPATCH_MAP(CCal2Ctrl)
  36.     // NOTE - ClassWizard will add and remove dispatch map entries
  37.     //    DO NOT EDIT what you see in these blocks of generated code !
  38.     //}}AFX_DISPATCH_MAP
  39.     DISP_FUNCTION_ID(CCal2Ctrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
  40. END_DISPATCH_MAP()
  41.  
  42.  
  43. /////////////////////////////////////////////////////////////////////////////
  44. // Event map
  45.  
  46. BEGIN_EVENT_MAP(CCal2Ctrl, COleControl)
  47.     //{{AFX_EVENT_MAP(CCal2Ctrl)
  48.     // NOTE - ClassWizard will add and remove event map entries
  49.     //    DO NOT EDIT what you see in these blocks of generated code !
  50.     //}}AFX_EVENT_MAP
  51. END_EVENT_MAP()
  52.  
  53.  
  54. /////////////////////////////////////////////////////////////////////////////
  55. // Property pages
  56.  
  57. // TODO: Add more property pages as needed.  Remember to increase the count!
  58. BEGIN_PROPPAGEIDS(CCal2Ctrl, 1)
  59.     PROPPAGEID(CCal2PropPage::guid)
  60. END_PROPPAGEIDS(CCal2Ctrl)
  61.  
  62.  
  63. /////////////////////////////////////////////////////////////////////////////
  64. // Initialize class factory and guid
  65.  
  66. IMPLEMENT_OLECREATE_EX(CCal2Ctrl, "CAL2.Cal2Ctrl.1",
  67.     0x3f12e83, 0x14a9, 0x11cf, 0x95, 0x2f, 0, 0x20, 0xaf, 0x6e, 0x90, 0x3f)
  68.  
  69.  
  70. /////////////////////////////////////////////////////////////////////////////
  71. // Type library ID and version
  72.  
  73. IMPLEMENT_OLETYPELIB(CCal2Ctrl, _tlid, _wVerMajor, _wVerMinor)
  74.  
  75.  
  76. /////////////////////////////////////////////////////////////////////////////
  77. // Interface IDs
  78.  
  79. const IID BASED_CODE IID_DCal2 =
  80.         { 0x3f12e81, 0x14a9, 0x11cf, { 0x95, 0x2f, 0, 0x20, 0xaf, 0x6e, 0x90, 0x3f } };
  81. const IID BASED_CODE IID_DCal2Events =
  82.         { 0x3f12e82, 0x14a9, 0x11cf, { 0x95, 0x2f, 0, 0x20, 0xaf, 0x6e, 0x90, 0x3f } };
  83.  
  84.  
  85. /////////////////////////////////////////////////////////////////////////////
  86. // Control type information
  87.  
  88. static const DWORD BASED_CODE _dwCal2OleMisc =
  89.     OLEMISC_ACTIVATEWHENVISIBLE |
  90.     OLEMISC_SETCLIENTSITEFIRST |
  91.     OLEMISC_INSIDEOUT |
  92.     OLEMISC_CANTLINKINSIDE |
  93.     OLEMISC_RECOMPOSEONRESIZE;
  94.  
  95. IMPLEMENT_OLECTLTYPE(CCal2Ctrl, IDS_CAL2, _dwCal2OleMisc)
  96.  
  97.  
  98. /////////////////////////////////////////////////////////////////////////////
  99. // CCal2Ctrl::CCal2CtrlFactory::UpdateRegistry -
  100. // Adds or removes system registry entries for CCal2Ctrl
  101.  
  102. BOOL CCal2Ctrl::CCal2CtrlFactory::UpdateRegistry(BOOL bRegister)
  103. {
  104.     if (bRegister)
  105.         return AfxOleRegisterControlClass(
  106.             AfxGetInstanceHandle(),
  107.             m_clsid,
  108.             m_lpszProgID,
  109.             IDS_CAL2,
  110.             IDB_CAL2,
  111.             FALSE,                      //  Not insertable
  112.             _dwCal2OleMisc,
  113.             _tlid,
  114.             _wVerMajor,
  115.             _wVerMinor);
  116.     else
  117.         return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
  118. }
  119.  
  120.  
  121. /////////////////////////////////////////////////////////////////////////////
  122. // Licensing strings
  123.  
  124. static const TCHAR BASED_CODE _szLicFileName[] = _T("Cal2.lic");
  125.  
  126. static const WCHAR BASED_CODE _szLicString[] =
  127.     L"Copyright (c) 1995 ";
  128.  
  129.  
  130. /////////////////////////////////////////////////////////////////////////////
  131. // CCal2Ctrl::CCal2CtrlFactory::VerifyUserLicense -
  132. // Checks for existence of a user license
  133.  
  134. BOOL CCal2Ctrl::CCal2CtrlFactory::VerifyUserLicense()
  135. {
  136.     return AfxVerifyLicFile(AfxGetInstanceHandle(), _szLicFileName,
  137.         _szLicString);
  138. }
  139.  
  140.  
  141. /////////////////////////////////////////////////////////////////////////////
  142. // CCal2Ctrl::CCal2CtrlFactory::GetLicenseKey -
  143. // Returns a runtime licensing key
  144.  
  145. BOOL CCal2Ctrl::CCal2CtrlFactory::GetLicenseKey(DWORD dwReserved,
  146.     BSTR FAR* pbstrKey)
  147. {
  148.     if (pbstrKey == NULL)
  149.         return FALSE;
  150.  
  151.     *pbstrKey = SysAllocString(_szLicString);
  152.     return (*pbstrKey != NULL);
  153. }
  154.  
  155.  
  156. /////////////////////////////////////////////////////////////////////////////
  157. // CCal2Ctrl::CCal2Ctrl - Constructor
  158.  
  159. CCal2Ctrl::CCal2Ctrl()
  160. {
  161.     InitializeIIDs(&IID_DCal2, &IID_DCal2Events);
  162.  
  163.     // TODO: Initialize your control's instance data here.
  164. }
  165.  
  166.  
  167. /////////////////////////////////////////////////////////////////////////////
  168. // CCal2Ctrl::~CCal2Ctrl - Destructor
  169.  
  170. CCal2Ctrl::~CCal2Ctrl()
  171. {
  172.     // TODO: Cleanup your control's instance data here.
  173. }
  174.  
  175.  
  176. /////////////////////////////////////////////////////////////////////////////
  177. // CCal2Ctrl::OnDraw - Drawing function
  178.  
  179. void CCal2Ctrl::OnDraw(
  180.             CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
  181. {
  182.     // TODO: Replace the following code with your own drawing code.
  183.     pdc->FillRect(rcBounds, CBrush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH)));
  184.     pdc->Ellipse(rcBounds);
  185. }
  186.  
  187.  
  188. /////////////////////////////////////////////////////////////////////////////
  189. // CCal2Ctrl::DoPropExchange - Persistence support
  190.  
  191. void CCal2Ctrl::DoPropExchange(CPropExchange* pPX)
  192. {
  193.     ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
  194.     COleControl::DoPropExchange(pPX);
  195.  
  196.     // TODO: Call PX_ functions for each persistent custom property.
  197.  
  198. }
  199.  
  200.  
  201. /////////////////////////////////////////////////////////////////////////////
  202. // CCal2Ctrl::OnResetState - Reset control to default state
  203.  
  204. void CCal2Ctrl::OnResetState()
  205. {
  206.     COleControl::OnResetState();  // Resets defaults found in DoPropExchange
  207.  
  208.     // TODO: Reset any other control state here.
  209. }
  210.  
  211.  
  212. /////////////////////////////////////////////////////////////////////////////
  213. // CCal2Ctrl::AboutBox - Display an "About" box to the user
  214.  
  215. void CCal2Ctrl::AboutBox()
  216. {
  217.     CDialog dlgAbout(IDD_ABOUTBOX_CAL2);
  218.     dlgAbout.DoModal();
  219. }
  220.  
  221.  
  222. /////////////////////////////////////////////////////////////////////////////
  223. // CCal2Ctrl message handlers
  224.