home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / mfc / database / daoctl / control / daoctl.cpp < prev    next >
C/C++ Source or Header  |  1998-03-26  |  7KB  |  269 lines

  1. // DaoEditCtl.cpp : Implementation of the CDaoEditCtrl OLE control class.
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-1998 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13. #include "stdafx.h"
  14. #include "DaoEdit.h"
  15. #include "DaoCtl.h"
  16. #include "DaoPpg.h"
  17.  
  18.  
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24.  
  25.  
  26. IMPLEMENT_DYNCREATE(CDaoEditCtrl, COleControl)
  27.  
  28.  
  29. /////////////////////////////////////////////////////////////////////////////
  30. // Message map
  31.  
  32. BEGIN_MESSAGE_MAP(CDaoEditCtrl, COleControl)
  33.     //{{AFX_MSG_MAP(CDaoEditCtrl)
  34.     ON_WM_KILLFOCUS()
  35.     ON_WM_CHAR()
  36.     ON_WM_KEYDOWN()
  37.     //}}AFX_MSG_MAP
  38.     ON_MESSAGE(OCM_COMMAND, OnOcmCommand)
  39.     ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
  40. END_MESSAGE_MAP()
  41.  
  42.  
  43. /////////////////////////////////////////////////////////////////////////////
  44. // Dispatch map
  45.  
  46. BEGIN_DISPATCH_MAP(CDaoEditCtrl, COleControl)
  47.     //{{AFX_DISPATCH_MAP(CDaoEditCtrl)
  48.     DISP_PROPERTY(CDaoEditCtrl, "FieldName", m_strFieldName, VT_BSTR)
  49.     DISP_DEFVALUE(CDaoEditCtrl, "Text")
  50.     DISP_STOCKPROP_TEXT()
  51.     DISP_STOCKPROP_BORDERSTYLE()
  52.     //}}AFX_DISPATCH_MAP
  53.     DISP_FUNCTION_ID(CDaoEditCtrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
  54. END_DISPATCH_MAP()
  55.  
  56.  
  57. /////////////////////////////////////////////////////////////////////////////
  58. // Event map
  59.  
  60. BEGIN_EVENT_MAP(CDaoEditCtrl, COleControl)
  61.     //{{AFX_EVENT_MAP(CDaoEditCtrl)
  62.     //}}AFX_EVENT_MAP
  63. END_EVENT_MAP()
  64.  
  65.  
  66. /////////////////////////////////////////////////////////////////////////////
  67. // Property pages
  68.  
  69. // TODO: Add more property pages as needed.  Remember to increase the count!
  70. BEGIN_PROPPAGEIDS(CDaoEditCtrl, 1)
  71.     PROPPAGEID(CDaoEditPropPage::guid)
  72. END_PROPPAGEIDS(CDaoEditCtrl)
  73.  
  74.  
  75. /////////////////////////////////////////////////////////////////////////////
  76. // Initialize class factory and guid
  77.  
  78. IMPLEMENT_OLECREATE_EX(CDaoEditCtrl, "DAOEDIT.DaoEditCtrl.1",
  79.     0x5fdfc3e3, 0xc360, 0x11ce, 0xa9, 0x87, 0, 0xaa, 0, 0x6e, 0xa4, 0xda)
  80.  
  81.  
  82. /////////////////////////////////////////////////////////////////////////////
  83. // Type library ID and version
  84.  
  85. IMPLEMENT_OLETYPELIB(CDaoEditCtrl, _tlid, _wVerMajor, _wVerMinor)
  86.  
  87.  
  88. /////////////////////////////////////////////////////////////////////////////
  89. // Interface IDs
  90.  
  91. const IID BASED_CODE IID_DDaoEdit =
  92.         { 0x5fdfc3e1, 0xc360, 0x11ce, { 0xa9, 0x87, 0, 0xaa, 0, 0x6e, 0xa4, 0xda } };
  93. const IID BASED_CODE IID_DDaoEditEvents =
  94.         { 0x5fdfc3e2, 0xc360, 0x11ce, { 0xa9, 0x87, 0, 0xaa, 0, 0x6e, 0xa4, 0xda } };
  95.  
  96.  
  97. /////////////////////////////////////////////////////////////////////////////
  98. // Control type information
  99.  
  100. static const DWORD BASED_CODE _dwDaoEditOleMisc =
  101.     OLEMISC_ACTIVATEWHENVISIBLE |
  102.     OLEMISC_SETCLIENTSITEFIRST |
  103.     OLEMISC_INSIDEOUT |
  104.     OLEMISC_CANTLINKINSIDE |
  105.     OLEMISC_RECOMPOSEONRESIZE;
  106.  
  107. IMPLEMENT_OLECTLTYPE(CDaoEditCtrl, IDS_DAOEDIT, _dwDaoEditOleMisc)
  108.  
  109.  
  110. /////////////////////////////////////////////////////////////////////////////
  111. // CDaoEditCtrl::CDaoEditCtrlFactory::UpdateRegistry -
  112. // Adds or removes system registry entries for CDaoEditCtrl
  113.  
  114. BOOL CDaoEditCtrl::CDaoEditCtrlFactory::UpdateRegistry(BOOL bRegister)
  115. {
  116.     if (bRegister)
  117.         return AfxOleRegisterControlClass(
  118.             AfxGetInstanceHandle(),
  119.             m_clsid,
  120.             m_lpszProgID,
  121.             IDS_DAOEDIT,
  122.             IDB_DAOEDIT,
  123.             FALSE,                      //  Not insertable
  124.             _dwDaoEditOleMisc,
  125.             _tlid,
  126.             _wVerMajor,
  127.             _wVerMinor);
  128.     else
  129.         return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
  130. }
  131.  
  132.  
  133. /////////////////////////////////////////////////////////////////////////////
  134. // CDaoEditCtrl::CDaoEditCtrl - Constructor
  135.  
  136. CDaoEditCtrl::CDaoEditCtrl()
  137. {
  138.     InitializeIIDs(&IID_DDaoEdit, &IID_DDaoEditEvents);
  139.  
  140.     m_bDirty = FALSE;
  141. }
  142.  
  143.  
  144. /////////////////////////////////////////////////////////////////////////////
  145. // CDaoEditCtrl::~CDaoEditCtrl - Destructor
  146.  
  147. CDaoEditCtrl::~CDaoEditCtrl()
  148. {
  149. }
  150.  
  151.  
  152. /////////////////////////////////////////////////////////////////////////////
  153. // CDaoEditCtrl::OnDraw - Drawing function
  154.  
  155. void CDaoEditCtrl::OnDraw(
  156.             CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
  157. {
  158.     DoSuperclassPaint(pdc, rcBounds);
  159. }
  160.  
  161.  
  162. /////////////////////////////////////////////////////////////////////////////
  163. // CDaoEditCtrl::DoPropExchange - Persistence support
  164.  
  165. void CDaoEditCtrl::DoPropExchange(CPropExchange* pPX)
  166. {
  167.     ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
  168.     COleControl::DoPropExchange(pPX);
  169.  
  170.     // TODO: Call PX_ functions for each persistent custom property.
  171.  
  172. }
  173.  
  174.  
  175. /////////////////////////////////////////////////////////////////////////////
  176. // CDaoEditCtrl::OnResetState - Reset control to default state
  177.  
  178. void CDaoEditCtrl::OnResetState()
  179. {
  180.     COleControl::OnResetState();  // Resets defaults found in DoPropExchange
  181.  
  182.     // TODO: Reset any other control state here.
  183. }
  184.  
  185.  
  186. /////////////////////////////////////////////////////////////////////////////
  187. // CDaoEditCtrl::AboutBox - Display an "About" box to the user
  188.  
  189. void CDaoEditCtrl::AboutBox()
  190. {
  191.     CDialog dlgAbout(IDD_ABOUTBOX_DAOEDIT);
  192.     dlgAbout.DoModal();
  193. }
  194.  
  195.  
  196. /////////////////////////////////////////////////////////////////////////////
  197. // CDaoEditCtrl::PreCreateWindow - Modify parameters for CreateWindowEx
  198.  
  199. BOOL CDaoEditCtrl::PreCreateWindow(CREATESTRUCT& cs)
  200. {
  201.     cs.lpszClass = _T("EDIT");
  202.     cs.style |= ES_AUTOHSCROLL;
  203.     return COleControl::PreCreateWindow(cs);
  204. }
  205.  
  206.  
  207. /////////////////////////////////////////////////////////////////////////////
  208. // CDaoEditCtrl::IsSubclassedControl - This is a subclassed control
  209.  
  210. BOOL CDaoEditCtrl::IsSubclassedControl()
  211. {
  212.     return TRUE;
  213. }
  214.  
  215.  
  216. /////////////////////////////////////////////////////////////////////////////
  217. // CDaoEditCtrl::OnOcmCommand - Handle command messages
  218.  
  219. LRESULT CDaoEditCtrl::OnOcmCommand(WPARAM wParam, LPARAM lParam)
  220. {
  221. #ifdef _WIN32
  222.     WORD wNotifyCode = HIWORD(wParam);
  223. #else
  224.     WORD wNotifyCode = HIWORD(lParam);
  225. #endif
  226.  
  227.     // TODO: Switch on wNotifyCode here.
  228.  
  229.     return 0;
  230. }
  231.  
  232.  
  233. /////////////////////////////////////////////////////////////////////////////
  234.  
  235.  
  236. void CDaoEditCtrl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
  237. {
  238.     if (nChar != VK_DELETE)
  239.     {
  240.         COleControl::OnKeyDown(nChar, nRepCnt, nFlags);
  241.         return;
  242.     }
  243.     if (BoundPropertyRequestEdit(DISPID_TEXT))
  244.     {
  245.         m_bDirty = TRUE;
  246.         COleControl::OnKeyDown(nChar, nRepCnt, nFlags);
  247.     }
  248. }
  249.  
  250. void CDaoEditCtrl::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
  251. {
  252.     if (BoundPropertyRequestEdit(DISPID_TEXT))
  253.     {
  254.         m_bDirty = TRUE;
  255.         COleControl::OnChar(nChar, nRepCnt, nFlags);
  256.     }
  257. }
  258.  
  259. void CDaoEditCtrl::OnKillFocus(CWnd* pNewWnd)
  260. {
  261.     COleControl::OnKillFocus(pNewWnd);
  262.  
  263.     if (m_bDirty)
  264.     {
  265.         BoundPropertyChanged(DISPID_TEXT);
  266.         m_bDirty = FALSE;
  267.     }
  268. }
  269.