home *** CD-ROM | disk | FTP | other *** search
/ ActiveX Programming Unleashed CD / AXU.iso / source / chap04 / lst43 / lst43ctl.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-26  |  5.9 KB  |  217 lines

  1. // Lst43Ctl.cpp : Implementation of the CLst43Ctrl OLE control class.
  2.  
  3. #include "stdafx.h"
  4. #include "lst43.h"
  5. #include "Lst43Ctl.h"
  6. #include "Lst43Ppg.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(CLst43Ctrl, COleControl)
  17.  
  18.  
  19. /////////////////////////////////////////////////////////////////////////////
  20. // Message map
  21.  
  22. BEGIN_MESSAGE_MAP(CLst43Ctrl, COleControl)
  23.     //{{AFX_MSG_MAP(CLst43Ctrl)
  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(CLst43Ctrl, COleControl)
  35.     //{{AFX_DISPATCH_MAP(CLst43Ctrl)
  36.     DISP_FUNCTION(CLst43Ctrl, "GetMachineName", GetMachineName, VT_BSTR, VTS_NONE)
  37.     //}}AFX_DISPATCH_MAP
  38.     DISP_FUNCTION_ID(CLst43Ctrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
  39. END_DISPATCH_MAP()
  40.  
  41.  
  42. /////////////////////////////////////////////////////////////////////////////
  43. // Event map
  44.  
  45. BEGIN_EVENT_MAP(CLst43Ctrl, COleControl)
  46.     //{{AFX_EVENT_MAP(CLst43Ctrl)
  47.     // NOTE - ClassWizard will add and remove event map entries
  48.     //    DO NOT EDIT what you see in these blocks of generated code !
  49.     //}}AFX_EVENT_MAP
  50. END_EVENT_MAP()
  51.  
  52.  
  53. /////////////////////////////////////////////////////////////////////////////
  54. // Property pages
  55.  
  56. // TODO: Add more property pages as needed.  Remember to increase the count!
  57. BEGIN_PROPPAGEIDS(CLst43Ctrl, 1)
  58.     PROPPAGEID(CLst43PropPage::guid)
  59. END_PROPPAGEIDS(CLst43Ctrl)
  60.  
  61.  
  62. /////////////////////////////////////////////////////////////////////////////
  63. // Initialize class factory and guid
  64.  
  65. IMPLEMENT_OLECREATE_EX(CLst43Ctrl, "LST43.Lst43Ctrl.1",
  66.     0x6b70dae, 0x1818, 0x11d0, 0xa6, 0xad, 0, 0xaa, 0, 0x60, 0x25, 0x53)
  67.  
  68.  
  69. /////////////////////////////////////////////////////////////////////////////
  70. // Type library ID and version
  71.  
  72. IMPLEMENT_OLETYPELIB(CLst43Ctrl, _tlid, _wVerMajor, _wVerMinor)
  73.  
  74.  
  75. /////////////////////////////////////////////////////////////////////////////
  76. // Interface IDs
  77.  
  78. const IID BASED_CODE IID_DLst43 =
  79.         { 0x6b70dac, 0x1818, 0x11d0, { 0xa6, 0xad, 0, 0xaa, 0, 0x60, 0x25, 0x53 } };
  80. const IID BASED_CODE IID_DLst43Events =
  81.         { 0x6b70dad, 0x1818, 0x11d0, { 0xa6, 0xad, 0, 0xaa, 0, 0x60, 0x25, 0x53 } };
  82.  
  83.  
  84. /////////////////////////////////////////////////////////////////////////////
  85. // Control type information
  86.  
  87. static const DWORD BASED_CODE _dwLst43OleMisc =
  88.     OLEMISC_ACTIVATEWHENVISIBLE |
  89.     OLEMISC_SETCLIENTSITEFIRST |
  90.     OLEMISC_INSIDEOUT |
  91.     OLEMISC_CANTLINKINSIDE |
  92.     OLEMISC_RECOMPOSEONRESIZE;
  93.  
  94. IMPLEMENT_OLECTLTYPE(CLst43Ctrl, IDS_LST43, _dwLst43OleMisc)
  95.  
  96.  
  97. /////////////////////////////////////////////////////////////////////////////
  98. // CLst43Ctrl::CLst43CtrlFactory::UpdateRegistry -
  99. // Adds or removes system registry entries for CLst43Ctrl
  100.  
  101. BOOL CLst43Ctrl::CLst43CtrlFactory::UpdateRegistry(BOOL bRegister)
  102. {
  103.     // TODO: Verify that your control follows apartment-model threading rules.
  104.     // Refer to MFC TechNote 64 for more information.
  105.     // If your control does not conform to the apartment-model rules, then
  106.     // you must modify the code below, changing the 6th parameter from
  107.     // afxRegApartmentThreading to 0.
  108.  
  109.     if (bRegister)
  110.         return AfxOleRegisterControlClass(
  111.             AfxGetInstanceHandle(),
  112.             m_clsid,
  113.             m_lpszProgID,
  114.             IDS_LST43,
  115.             IDB_LST43,
  116.             afxRegApartmentThreading,
  117.             _dwLst43OleMisc,
  118.             _tlid,
  119.             _wVerMajor,
  120.             _wVerMinor);
  121.     else
  122.         return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
  123. }
  124.  
  125.  
  126. /////////////////////////////////////////////////////////////////////////////
  127. // CLst43Ctrl::CLst43Ctrl - Constructor
  128.  
  129. CLst43Ctrl::CLst43Ctrl()
  130. {
  131.     InitializeIIDs(&IID_DLst43, &IID_DLst43Events);
  132.  
  133.     // TODO: Initialize your control's instance data here.
  134. }
  135.  
  136.  
  137. /////////////////////////////////////////////////////////////////////////////
  138. // CLst43Ctrl::~CLst43Ctrl - Destructor
  139.  
  140. CLst43Ctrl::~CLst43Ctrl()
  141. {
  142.     // TODO: Cleanup your control's instance data here.
  143. }
  144.  
  145.  
  146. /////////////////////////////////////////////////////////////////////////////
  147. // CLst43Ctrl::OnDraw - Drawing function
  148.  
  149. void CLst43Ctrl::OnDraw(
  150.             CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
  151. {
  152.     // TODO: Replace the following code with your own drawing code.
  153.     pdc->FillRect(rcBounds, CBrush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH)));
  154.     pdc->Ellipse(rcBounds);
  155. }
  156.  
  157.  
  158. /////////////////////////////////////////////////////////////////////////////
  159. // CLst43Ctrl::DoPropExchange - Persistence support
  160.  
  161. void CLst43Ctrl::DoPropExchange(CPropExchange* pPX)
  162. {
  163.     ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
  164.     COleControl::DoPropExchange(pPX);
  165.  
  166.     // TODO: Call PX_ functions for each persistent custom property.
  167.  
  168. }
  169.  
  170.  
  171. /////////////////////////////////////////////////////////////////////////////
  172. // CLst43Ctrl::OnResetState - Reset control to default state
  173.  
  174. void CLst43Ctrl::OnResetState()
  175. {
  176.     COleControl::OnResetState();  // Resets defaults found in DoPropExchange
  177.  
  178.     // TODO: Reset any other control state here.
  179. }
  180.  
  181.  
  182. /////////////////////////////////////////////////////////////////////////////
  183. // CLst43Ctrl::AboutBox - Display an "About" box to the user
  184.  
  185. void CLst43Ctrl::AboutBox()
  186. {
  187.     CDialog dlgAbout(IDD_ABOUTBOX_LST43);
  188.     dlgAbout.DoModal();
  189. }
  190.  
  191.  
  192. /////////////////////////////////////////////////////////////////////////////
  193. // CLst43Ctrl message handlers
  194.  
  195. BSTR CLst43Ctrl::GetMachineName() 
  196. {
  197.     CString strResult;
  198.     ULONG ulLen;
  199.  
  200.     char *lpName;
  201.  
  202.     lpName = new char[MAX_PATH];
  203.     ulLen = MAX_PATH;
  204.  
  205.     GetComputerName(lpName, &ulLen );
  206.     strResult = lpName;
  207.     delete [] lpName;
  208.  
  209.     return strResult.AllocSysString();
  210. }
  211.  
  212.  
  213. BOOL CLst43Ctrl::IsInvokeAllowed(DISPID dispid)
  214. {
  215.     return TRUE;
  216. }
  217.