// BarCodeCtrl.cpp : Implementation of the CBarCodeCtrl ActiveX Control class. #include "stdafx.h" #include "BarCode.h" #include "BarCodeCtrl.h" #include "BarCodePropPage.h" #include ".\barcodectrl.h" #ifdef _DEBUG #define new DEBUG_NEW #endif IMPLEMENT_DYNCREATE(CBarCodeCtrl, COleControl) // Message map BEGIN_MESSAGE_MAP(CBarCodeCtrl, COleControl) ON_MESSAGE(OCM_COMMAND, OnOcmCommand) ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties) ON_WM_PAINT() END_MESSAGE_MAP() // Dispatch map BEGIN_DISPATCH_MAP(CBarCodeCtrl, COleControl) DISP_PROPERTY_PARAM_ID(CBarCodeCtrl, "Code", dispidCode, GetCode, SetCode, VT_BSTR, VTS_PBSTR) /*DISP_STOCKPROP_TEXT()*/ DISP_STOCKPROP_CAPTION() DISP_STOCKPROP_TEXT() END_DISPATCH_MAP() // Event map BEGIN_EVENT_MAP(CBarCodeCtrl, COleControl) END_EVENT_MAP() // Property pages // TODO: Add more property pages as needed. Remember to increase the count! BEGIN_PROPPAGEIDS(CBarCodeCtrl, 1) PROPPAGEID(CBarCodePropPage::guid) END_PROPPAGEIDS(CBarCodeCtrl) // Initialize class factory and guid IMPLEMENT_OLECREATE_EX(CBarCodeCtrl, "BARCODE.BarCodeCtrl.1", 0x88ea1f15, 0xebf6, 0x4fc1, 0x8b, 0xb3, 0xb2, 0x33, 0x89, 0x17, 0x19, 0x73) // Type library ID and version IMPLEMENT_OLETYPELIB(CBarCodeCtrl, _tlid, _wVerMajor, _wVerMinor) // Interface IDs const IID BASED_CODE IID_DBarCode = { 0x599D97AD, 0xB74B, 0x4AF4, { 0xB0, 0x49, 0x3A, 0x69, 0x2F, 0x78, 0x66, 0xB1 } }; const IID BASED_CODE IID_DBarCodeEvents = { 0xAFA647B6, 0x711B, 0x4959, { 0xAE, 0x40, 0x50, 0xB8, 0x2, 0x87, 0x41, 0x7E } }; // Control type information static const DWORD BASED_CODE _dwBarCodeOleMisc = OLEMISC_ACTIVATEWHENVISIBLE | OLEMISC_SETCLIENTSITEFIRST | OLEMISC_INSIDEOUT | OLEMISC_CANTLINKINSIDE | OLEMISC_RECOMPOSEONRESIZE; IMPLEMENT_OLECTLTYPE(CBarCodeCtrl, IDS_BARCODE, _dwBarCodeOleMisc) // CBarCodeCtrl::CBarCodeCtrlFactory::UpdateRegistry - // Adds or removes system registry entries for CBarCodeCtrl BOOL CBarCodeCtrl::CBarCodeCtrlFactory::UpdateRegistry(BOOL bRegister) { // TODO: Verify that your control follows apartment-model threading rules. // Refer to MFC TechNote 64 for more information. // If your control does not conform to the apartment-model rules, then // you must modify the code below, changing the 6th parameter from // afxRegApartmentThreading to 0. if (bRegister) return AfxOleRegisterControlClass( AfxGetInstanceHandle(), m_clsid, m_lpszProgID, IDS_BARCODE, IDB_BARCODE, afxRegApartmentThreading, _dwBarCodeOleMisc, _tlid, _wVerMajor, _wVerMinor); else return AfxOleUnregisterClass(m_clsid, m_lpszProgID); } // CBarCodeCtrl::CBarCodeCtrl - Constructor CBarCodeCtrl::CBarCodeCtrl() { InitializeIIDs(&IID_DBarCode, &IID_DBarCodeEvents); // TODO: Initialize your control's instance data here. } // CBarCodeCtrl::~CBarCodeCtrl - Destructor CBarCodeCtrl::~CBarCodeCtrl() { // TODO: Cleanup your control's instance data here. } // CBarCodeCtrl::OnDraw - Drawing function void CBarCodeCtrl::OnDraw( CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid) { if (!pdc) return; DoSuperclassPaint(pdc, rcBounds); } // CBarCodeCtrl::DoPropExchange - Persistence support void CBarCodeCtrl::DoPropExchange(CPropExchange* pPX) { ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor)); COleControl::DoPropExchange(pPX); // TODO: Call PX_ functions for each persistent custom property. } // CBarCodeCtrl::OnResetState - Reset control to default state void CBarCodeCtrl::OnResetState() { COleControl::OnResetState(); // Resets defaults found in DoPropExchange // TODO: Reset any other control state here. } // CBarCodeCtrl::PreCreateWindow - Modify parameters for CreateWindowEx BOOL CBarCodeCtrl::PreCreateWindow(CREATESTRUCT& cs) { cs.lpszClass = _T("STATIC"); return COleControl::PreCreateWindow(cs); } // CBarCodeCtrl::IsSubclassedControl - This is a subclassed control BOOL CBarCodeCtrl::IsSubclassedControl() { return TRUE; } // CBarCodeCtrl::OnOcmCommand - Handle command messages LRESULT CBarCodeCtrl::OnOcmCommand(WPARAM wParam, LPARAM lParam) { #ifdef _WIN32 WORD wNotifyCode = HIWORD(wParam); #else WORD wNotifyCode = HIWORD(lParam); #endif // TODO: Switch on wNotifyCode here. return 0; } // CBarCodeCtrl message handlers BSTR CBarCodeCtrl::GetCode(BSTR* code) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); // TODO: Add your dispatch handler code here CString strResult; strResult = m_Code.GetCode(); return strResult.AllocSysString(); } void CBarCodeCtrl::SetCode(BSTR* code, LPCTSTR newVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); // TODO: Add your property handler code here m_Code.SetCode(newVal); SetModifiedFlag(); } /*BSTR CBarCodeCtrl::Getcc() { AFX_MANAGE_STATE(AfxGetStaticModuleState()); CString strResult(m_Code); return strResult.AllocSysString(); } void CBarCodeCtrl::Setcc(LPCTSTR newVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); //for(int i=0;i<7;i++) // m_Code[i] = newVal[i]; CString Str(newVal); //m_Code = TEXT(newVal); //strcpy(m_Code,Str); //InvalidateControl(); //MessageBox(Str); SetModifiedFlag(); }*/ void CBarCodeCtrl::OnPaint() { CPaintDC dc(this); RECT ClientRect; CBrush WhiteBrush(RGB(255,255,255)); GetClientRect(&ClientRect); // clears the background first dc.FillRect(&ClientRect,&WhiteBrush); m_Code.Draw(dc); WhiteBrush.DeleteObject(); } void CBarCodeCtrl::OnTextChanged() { // TODO: Add your specialized code here and/or call the base class CString Text = InternalGetText(); m_Code.SetCode(Text); InvalidateControl(); COleControl::OnTextChanged(); }