彩票走势图

Barcode Xpress使用教程:如何在Visual C++中作为COM对象使用(2)

原创|行业资讯|编辑:郝浩|2013-09-25 10:12:10.000|阅读 241 次

概述:在提供了容器支持如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@pclwef.cn

文章转载自:慧都控件

为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP