BarCodeCtrl.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. // BarCodeCtrl.cpp : Implementation of the CBarCodeCtrl ActiveX Control class.
  2. #include "stdafx.h"
  3. #include "BarCode.h"
  4. #include "BarCodeCtrl.h"
  5. #include "BarCodePropPage.h"
  6. #include ".\barcodectrl.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #endif
  10. IMPLEMENT_DYNCREATE(CBarCodeCtrl, COleControl)
  11. // Message map
  12. BEGIN_MESSAGE_MAP(CBarCodeCtrl, COleControl)
  13. ON_MESSAGE(OCM_COMMAND, OnOcmCommand)
  14. ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
  15. ON_WM_PAINT()
  16. END_MESSAGE_MAP()
  17. // Dispatch map
  18. BEGIN_DISPATCH_MAP(CBarCodeCtrl, COleControl)
  19. DISP_PROPERTY_PARAM_ID(CBarCodeCtrl, "Code", dispidCode, GetCode, SetCode, VT_BSTR, VTS_PBSTR)
  20. /*DISP_STOCKPROP_TEXT()*/
  21. DISP_STOCKPROP_CAPTION()
  22. DISP_STOCKPROP_TEXT()
  23. END_DISPATCH_MAP()
  24. // Event map
  25. BEGIN_EVENT_MAP(CBarCodeCtrl, COleControl)
  26. END_EVENT_MAP()
  27. // Property pages
  28. // TODO: Add more property pages as needed. Remember to increase the count!
  29. BEGIN_PROPPAGEIDS(CBarCodeCtrl, 1)
  30. PROPPAGEID(CBarCodePropPage::guid)
  31. END_PROPPAGEIDS(CBarCodeCtrl)
  32. // Initialize class factory and guid
  33. IMPLEMENT_OLECREATE_EX(CBarCodeCtrl, "BARCODE.BarCodeCtrl.1",
  34. 0x88ea1f15, 0xebf6, 0x4fc1, 0x8b, 0xb3, 0xb2, 0x33, 0x89, 0x17, 0x19, 0x73)
  35. // Type library ID and version
  36. IMPLEMENT_OLETYPELIB(CBarCodeCtrl, _tlid, _wVerMajor, _wVerMinor)
  37. // Interface IDs
  38. const IID BASED_CODE IID_DBarCode =
  39. { 0x599D97AD, 0xB74B, 0x4AF4, { 0xB0, 0x49, 0x3A, 0x69, 0x2F, 0x78, 0x66, 0xB1 } };
  40. const IID BASED_CODE IID_DBarCodeEvents =
  41. { 0xAFA647B6, 0x711B, 0x4959, { 0xAE, 0x40, 0x50, 0xB8, 0x2, 0x87, 0x41, 0x7E } };
  42. // Control type information
  43. static const DWORD BASED_CODE _dwBarCodeOleMisc =
  44. OLEMISC_ACTIVATEWHENVISIBLE |
  45. OLEMISC_SETCLIENTSITEFIRST |
  46. OLEMISC_INSIDEOUT |
  47. OLEMISC_CANTLINKINSIDE |
  48. OLEMISC_RECOMPOSEONRESIZE;
  49. IMPLEMENT_OLECTLTYPE(CBarCodeCtrl, IDS_BARCODE, _dwBarCodeOleMisc)
  50. // CBarCodeCtrl::CBarCodeCtrlFactory::UpdateRegistry -
  51. // Adds or removes system registry entries for CBarCodeCtrl
  52. BOOL CBarCodeCtrl::CBarCodeCtrlFactory::UpdateRegistry(BOOL bRegister)
  53. {
  54. // TODO: Verify that your control follows apartment-model threading rules.
  55. // Refer to MFC TechNote 64 for more information.
  56. // If your control does not conform to the apartment-model rules, then
  57. // you must modify the code below, changing the 6th parameter from
  58. // afxRegApartmentThreading to 0.
  59. if (bRegister)
  60. return AfxOleRegisterControlClass(
  61. AfxGetInstanceHandle(),
  62. m_clsid,
  63. m_lpszProgID,
  64. IDS_BARCODE,
  65. IDB_BARCODE,
  66. afxRegApartmentThreading,
  67. _dwBarCodeOleMisc,
  68. _tlid,
  69. _wVerMajor,
  70. _wVerMinor);
  71. else
  72. return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
  73. }
  74. // CBarCodeCtrl::CBarCodeCtrl - Constructor
  75. CBarCodeCtrl::CBarCodeCtrl()
  76. {
  77. InitializeIIDs(&IID_DBarCode, &IID_DBarCodeEvents);
  78. // TODO: Initialize your control's instance data here.
  79. }
  80. // CBarCodeCtrl::~CBarCodeCtrl - Destructor
  81. CBarCodeCtrl::~CBarCodeCtrl()
  82. {
  83. // TODO: Cleanup your control's instance data here.
  84. }
  85. // CBarCodeCtrl::OnDraw - Drawing function
  86. void CBarCodeCtrl::OnDraw(
  87. CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
  88. {
  89. if (!pdc)
  90. return;
  91. DoSuperclassPaint(pdc, rcBounds);
  92. }
  93. // CBarCodeCtrl::DoPropExchange - Persistence support
  94. void CBarCodeCtrl::DoPropExchange(CPropExchange* pPX)
  95. {
  96. ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
  97. COleControl::DoPropExchange(pPX);
  98. // TODO: Call PX_ functions for each persistent custom property.
  99. }
  100. // CBarCodeCtrl::OnResetState - Reset control to default state
  101. void CBarCodeCtrl::OnResetState()
  102. {
  103. COleControl::OnResetState(); // Resets defaults found in DoPropExchange
  104. // TODO: Reset any other control state here.
  105. }
  106. // CBarCodeCtrl::PreCreateWindow - Modify parameters for CreateWindowEx
  107. BOOL CBarCodeCtrl::PreCreateWindow(CREATESTRUCT& cs)
  108. {
  109. cs.lpszClass = _T("STATIC");
  110. return COleControl::PreCreateWindow(cs);
  111. }
  112. // CBarCodeCtrl::IsSubclassedControl - This is a subclassed control
  113. BOOL CBarCodeCtrl::IsSubclassedControl()
  114. {
  115. return TRUE;
  116. }
  117. // CBarCodeCtrl::OnOcmCommand - Handle command messages
  118. LRESULT CBarCodeCtrl::OnOcmCommand(WPARAM wParam, LPARAM lParam)
  119. {
  120. #ifdef _WIN32
  121. WORD wNotifyCode = HIWORD(wParam);
  122. #else
  123. WORD wNotifyCode = HIWORD(lParam);
  124. #endif
  125. // TODO: Switch on wNotifyCode here.
  126. return 0;
  127. }
  128. // CBarCodeCtrl message handlers
  129. BSTR CBarCodeCtrl::GetCode(BSTR* code)
  130. {
  131. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  132. // TODO: Add your dispatch handler code here
  133. CString strResult;
  134. strResult = m_Code.GetCode();
  135. return strResult.AllocSysString();
  136. }
  137. void CBarCodeCtrl::SetCode(BSTR* code, LPCTSTR newVal)
  138. {
  139. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  140. // TODO: Add your property handler code here
  141. m_Code.SetCode(newVal);
  142. SetModifiedFlag();
  143. }
  144. /*BSTR CBarCodeCtrl::Getcc()
  145. {
  146. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  147. CString strResult(m_Code);
  148. return strResult.AllocSysString();
  149. }
  150. void CBarCodeCtrl::Setcc(LPCTSTR newVal)
  151. {
  152. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  153. //for(int i=0;i<7;i++)
  154. // m_Code[i] = newVal[i];
  155. CString Str(newVal);
  156. //m_Code = TEXT(newVal);
  157. //strcpy(m_Code,Str);
  158. //InvalidateControl();
  159. //MessageBox(Str);
  160. SetModifiedFlag();
  161. }*/
  162. void CBarCodeCtrl::OnPaint()
  163. {
  164. CPaintDC dc(this);
  165. RECT ClientRect;
  166. CBrush WhiteBrush(RGB(255,255,255));
  167. GetClientRect(&ClientRect);
  168. // clears the background first
  169. dc.FillRect(&ClientRect,&WhiteBrush);
  170. m_Code.Draw(dc);
  171. WhiteBrush.DeleteObject();
  172. }
  173. void CBarCodeCtrl::OnTextChanged()
  174. {
  175. // TODO: Add your specialized code here and/or call the base class
  176. CString Text = InternalGetText();
  177. m_Code.SetCode(Text);
  178. InvalidateControl();
  179. COleControl::OnTextChanged();
  180. }