home *** CD-ROM | disk | FTP | other *** search
/ Building OCXs / Building_OCXs_Que_1995.iso / code / ch11 / buttoctl.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-02  |  6.2 KB  |  230 lines

  1. // buttoctl.cpp : Implementation of the CButtonCtrl OLE control class.
  2.  
  3. #include "stdafx.h"
  4. #include "button.h"
  5. #include "buttoctl.h"
  6. #include "buttoppg.h"
  7.  
  8.  
  9. #ifdef _DEBUG
  10. #undef THIS_FILE
  11. static char BASED_CODE THIS_FILE[] = __FILE__;
  12. #endif
  13.  
  14.  
  15. IMPLEMENT_DYNCREATE(CButtonCtrl, COleControl)
  16.  
  17.  
  18. /////////////////////////////////////////////////////////////////////////////
  19. // Message map
  20.  
  21. BEGIN_MESSAGE_MAP(CButtonCtrl, COleControl)
  22.     //{{AFX_MSG_MAP(CButtonCtrl)
  23.     // NOTE - ClassWizard will add and remove message map entries
  24.     //    DO NOT EDIT what you see in these blocks of generated code !
  25.     ON_MESSAGE(OCM_COMMAND, OnOcmCommand)
  26.     //}}AFX_MSG_MAP
  27.     ON_OLEVERB(AFX_IDS_VERB_EDIT, OnEdit)
  28.     ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
  29. END_MESSAGE_MAP()
  30.  
  31.  
  32. /////////////////////////////////////////////////////////////////////////////
  33. // Dispatch map
  34.  
  35. BEGIN_DISPATCH_MAP(CButtonCtrl, COleControl)
  36.     //{{AFX_DISPATCH_MAP(CButtonCtrl)
  37.     // NOTE - ClassWizard will add and remove dispatch map entries
  38.     //    DO NOT EDIT what you see in these blocks of generated code !
  39.     //}}AFX_DISPATCH_MAP
  40.     DISP_FUNCTION_ID(CButtonCtrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
  41. END_DISPATCH_MAP()
  42.  
  43.  
  44. /////////////////////////////////////////////////////////////////////////////
  45. // Event map
  46.  
  47. BEGIN_EVENT_MAP(CButtonCtrl, COleControl)
  48.     //{{AFX_EVENT_MAP(CButtonCtrl)
  49.     EVENT_STOCK_CLICK()
  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(CButtonCtrl, 1)
  59.     PROPPAGEID(CButtonPropPage::guid)
  60. END_PROPPAGEIDS(CButtonCtrl)
  61.  
  62.  
  63. /////////////////////////////////////////////////////////////////////////////
  64. // Initialize class factory and guid
  65.  
  66. IMPLEMENT_OLECREATE_EX(CButtonCtrl, "BUTTON.ButtonCtrl.1",
  67.     0x56a2c5a0, 0x240a, 0x11ce, 0x96, 0xf, 0x52, 0x41, 0x53, 0x48, 0x0, 0x5)
  68.  
  69.  
  70. /////////////////////////////////////////////////////////////////////////////
  71. // Type library ID and version
  72.  
  73. IMPLEMENT_OLETYPELIB(CButtonCtrl, _tlid, _wVerMajor, _wVerMinor)
  74.  
  75.  
  76. /////////////////////////////////////////////////////////////////////////////
  77. // Interface IDs
  78.  
  79. const IID BASED_CODE IID_DButton =
  80.         { 0x56a2c5a1, 0x240a, 0x11ce, { 0x96, 0xf, 0x52, 0x41, 0x53, 0x48, 0x0, 0x5 } };
  81. const IID BASED_CODE IID_DButtonEvents =
  82.         { 0x56a2c5a2, 0x240a, 0x11ce, { 0x96, 0xf, 0x52, 0x41, 0x53, 0x48, 0x0, 0x5 } };
  83.  
  84.  
  85. /////////////////////////////////////////////////////////////////////////////
  86. // Control type information
  87.  
  88. static const DWORD BASED_CODE _dwButtonOleMisc =
  89.     OLEMISC_ACTIVATEWHENVISIBLE |
  90.     OLEMISC_SETCLIENTSITEFIRST |
  91.     OLEMISC_INSIDEOUT |
  92.     OLEMISC_CANTLINKINSIDE |
  93.     OLEMISC_RECOMPOSEONRESIZE;
  94.  
  95. IMPLEMENT_OLECTLTYPE(CButtonCtrl, IDS_BUTTON, _dwButtonOleMisc)
  96.  
  97.  
  98. /////////////////////////////////////////////////////////////////////////////
  99. // CButtonCtrl::CButtonCtrlFactory::UpdateRegistry -
  100. // Adds or removes system registry entries for CButtonCtrl
  101.  
  102. BOOL CButtonCtrl::CButtonCtrlFactory::UpdateRegistry(BOOL bRegister)
  103. {
  104.     if (bRegister)
  105.         return AfxOleRegisterControlClass(
  106.             AfxGetInstanceHandle(),
  107.             m_clsid,
  108.             m_lpszProgID,
  109.             IDS_BUTTON,
  110.             IDB_BUTTON,
  111.             TRUE,                       //  Insertable
  112.             _dwButtonOleMisc,
  113.             _tlid,
  114.             _wVerMajor,
  115.             _wVerMinor);
  116.     else
  117.         return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
  118. }
  119.  
  120.  
  121. /////////////////////////////////////////////////////////////////////////////
  122. // CButtonCtrl::CButtonCtrl - Constructor
  123.  
  124. CButtonCtrl::CButtonCtrl()
  125. {
  126.     InitializeIIDs(&IID_DButton, &IID_DButtonEvents);
  127.  
  128.     // TODO: Initialize your control's instance data here.
  129. }
  130.  
  131.  
  132. /////////////////////////////////////////////////////////////////////////////
  133. // CButtonCtrl::~CButtonCtrl - Destructor
  134.  
  135. CButtonCtrl::~CButtonCtrl()
  136. {
  137.     // TODO: Cleanup your control's instance data here.
  138. }
  139.  
  140.  
  141. /////////////////////////////////////////////////////////////////////////////
  142. // CButtonCtrl::OnDraw - Drawing function
  143.  
  144. void CButtonCtrl::OnDraw(
  145.             CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
  146. {
  147.     DoSuperclassPaint(pdc, rcBounds);
  148. }
  149.  
  150.  
  151. /////////////////////////////////////////////////////////////////////////////
  152. // CButtonCtrl::DoPropExchange - Persistence support
  153.  
  154. void CButtonCtrl::DoPropExchange(CPropExchange* pPX)
  155. {
  156.     ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
  157.     COleControl::DoPropExchange(pPX);
  158.  
  159.     // TODO: Call PX_ functions for each persistent custom property.
  160.  
  161. }
  162.  
  163.  
  164. /////////////////////////////////////////////////////////////////////////////
  165. // CButtonCtrl::OnResetState - Reset control to default state
  166.  
  167. void CButtonCtrl::OnResetState()
  168. {
  169.     COleControl::OnResetState();  // Resets defaults found in DoPropExchange
  170.  
  171.     // TODO: Reset any other control state here.
  172. }
  173.  
  174.  
  175. /////////////////////////////////////////////////////////////////////////////
  176. // CButtonCtrl::AboutBox - Display an "About" box to the user
  177.  
  178. void CButtonCtrl::AboutBox()
  179. {
  180.     CDialog dlgAbout(IDD_ABOUTBOX_BUTTON);
  181.     dlgAbout.DoModal();
  182. }
  183.  
  184.  
  185. /////////////////////////////////////////////////////////////////////////////
  186. // CButtonCtrl::PreCreateWindow - Modify parameters for CreateWindowEx
  187.  
  188. BOOL CButtonCtrl::PreCreateWindow(CREATESTRUCT& cs)
  189. {
  190.     cs.lpszClass = _T("BUTTON");
  191.     return COleControl::PreCreateWindow(cs);
  192. }
  193.  
  194.  
  195. /////////////////////////////////////////////////////////////////////////////
  196. // CButtonCtrl::GetSuperWndProcAddr - Provide storage for window proc
  197.  
  198. WNDPROC* CButtonCtrl::GetSuperWndProcAddr(void)
  199. {
  200.     static WNDPROC NEAR pfnSuper;
  201.     return &pfnSuper;
  202. }
  203.  
  204.  
  205. /////////////////////////////////////////////////////////////////////////////
  206. // CButtonCtrl::OnOcmCommand - Handle command messages
  207.  
  208. LRESULT CButtonCtrl::OnOcmCommand(WPARAM wParam, LPARAM lParam)
  209. {
  210. #ifdef _WIN32
  211.     WORD wNotifyCode = HIWORD(wParam);
  212. #else
  213.     WORD wNotifyCode = HIWORD(lParam);
  214. #endif
  215.  
  216.     // TODO: Switch on wNotifyCode here.
  217.     switch (wNotifyCode )
  218.     {
  219.         // Issue a message when the button is clicked
  220.         case BN_CLICKED :    MessageBox("Button Clicked");
  221.                             break;
  222.     }
  223.  
  224.     return 0;
  225. }
  226.  
  227.  
  228. /////////////////////////////////////////////////////////////////////////////
  229. // CButtonCtrl message handlers
  230.