原創|行業資訊|編輯:郝浩|2013-09-25 10:12:10.000|閱讀 295 次
概述:在提供了容器支持如Visual Basic或Visual C++的開發環境中,barcode Xpress可以被作為一個ActiveX控件使用。在Visual C++中如何將Barcode Xpress作為一個導入的COM 對象使用呢?下面來具體的討論一下。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
在前面的文章《Barcode Xpress使用教程:如何在Visual C++中作為COM對象使用(1)》中已經對在Visual C++中如何將Barcode Xpress作為一個導入的COM 對象使用的步驟做了一些講解,下面將繼續上文。
三、初始化COM
在COM函數可以被調用之前,這個必須先初始化COM庫,并且在程序退出之前必須關閉。在ReadBarcodeFromDIB.cpp文件中像下面這樣說明:
// CReadBarcodeFromDIBApp initialization
BOOL CReadBarcodeFromDIBApp::InitInstance()
{
// Initialize the COM library on the current apartment and identify
// the currency model as single-thread apartment (STA). Applications
// must initialize the COM
// library before they can call COM library functions other than
// CoGetMalloc and memory allocation functions.
HRESULT hRes = CoInitialize(NULL);
AfxEnableControlContainer();
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
CReadBarcodeFromDIBDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
// Closes the COM library on the current apartment,
// unloads all DLLs loaded by apartment,
// frees any other resources that the apartment maintains, and
// forces all RPC connections on the apartment to close.
CoUninitialize();
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}
四、創建BarcodeXpress COM對象
要使用BarcodeXpress,需要創建一個BarcodeXpress COM實例。在對象被創建之后,對象的屬性和方法可以用于創建你的掃描應用程序。在ReadBarcodeFromDIB項目中,這個COM對象在 ReadBarcodeFromDIBDlg.cpp文件中如下創建:
// CReadBarcodeFromDIBDlg message handlers
BOOL CReadBarcodeFromDIBDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
CWnd* pControl = NULL;
pControl = GetDlgItem(Description);
if (pControl)
{
pControl->SetWindowText(lpctstrDescription);
}
CRect oIXArea;
oIXArea.left = 25;
oIXArea.top = 215;
oIXArea.right = 725;
oIXArea.bottom = 636;
// Create an ImagXpress Object
m_ppCImagXpress = new CImagXpress(this, 1, (long) m_hWnd,
oIXArea.left, oIXArea.top, oIXArea.Width(), oIXArea.Height());
m_pImagXpress = m_ppCImagXpress->pImagXpress;
m_pImagXpress->PutCtlVisible(true);
m_pImagXpress->AutoSize = ISIZE_BestFit;
m_pImagXpress->ScrollBars = SB_Both;
m_pImagXpress->MenuSetEnabled(Menu_Context,TOOL_None, true);
// **Initialize Barcode. You must call BC_Open before
// **creating the first BarcodeXpress COM object. You cannot distribute applications using
// **BarcodeXpress COM objects without valid unlock codes.
// Create a BarcodeXpress class object. The BarcodeXpress
// class object automatically creates a Barcode Xpress
// COM object.
m_ppIBarcodeXpress = new CBarcodeXpress(this, 1);
// The SetSolutionName, SetSolutionKey and possibly the SetOEMLicenseKey method must be
// called to distribute the runtime. Note that the SolutionName, SolutionKey and
// OEMLicenseKey values shown below are only examples.
//
//m_pBarcodeXpress->SetSolutionName("YourSolutionName");
//m_pBarcodeXpress->SetSolutionKey(12345, 12345, 12345, 12345);
//m_pBarcodeXpress->SetOEMLicenseKey("1.0.AStringForOEMLicensingContactAccusoftSalesForMoreInformation...");
//
//m_pImagXpress->SetSolutionName("YourSolutionName");
//m_pImagXpress->SetSolutionKey(12345, 12345, 12345, 12345);
//m_pImagXpress->SetOEMLicenseKey("1.0.AStringForOEMLicensingContactAccusoftSalesForMoreInformation...");
// Get the pointer to the created BarcodeXpress Barcode COM object.
// This is the pointer that you will use to access BarcodeXpress
// Barcode properties and methods.
m_pBarcodeXpress = m_ppIBarcodeXpress->pBarcodeXpress;
// Close the BarcodeXpress Barcode initialization.
// You must call this AFTER creating the first BarcodeXpress Barcode
// COM object
m_1D.SetCheck(BST_CHECKED);
m_selection = 0;
m_pImagXpress->FileName = "..\\..\\..\\..\\..\\..\\Common\\Images\\Barcode All Supported Types.tif";
return TRUE; // return TRUE unless you set the focus to a control
}
>>>Barcode Xpress 下載
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@ke049m.cn
文章轉載自:慧都控件