彩票走势图

图像处理工具包ImagXpress使用教程:作为COM对象导入ImagXpress

原创|使用教程|编辑:郝浩|2013-07-23 13:53:11.000|阅读 420 次

概述:ImagXpress 是世界上最先进的彩色映像和照片图像处理工具包,有着.NET、COM、VC三种组件形式。本文主要来看看如何将ImagXpress作为一个COM对象导入 。

# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>

相关链接:

本文主要来看看如何将ImagXpress作为一个COM对象导入,将对步骤进行详细的讲解以及给出示例源码,主要步骤如下:

1、导入控件到Visual C + +中

#import指令行可以被添加到stdafx.h文件中来提供相应的功能给在项目中所有的源。

// This code demonstrates the #import directive used in the stdafx.h file 
#define AFX_STDAFX_H__B0A9FE69_3B8B_11D3_9CFE_00400543FF49__INCLUDED_
#if _MSC_VER= 1000
#pragma once
#endif // _MSC_VER >= 1000
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
#include <afxwin.h> // MFC core and standard components
#include <afxext.h> // MFC extensions
#include <afxdisp.h> // MFC OLE automation classes
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h> // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT
#import Accusoft.ImagXpress12.ActiveX.dll
//{{AFX_INSERT_LOCATION}}
//Microsoft Developer Studio will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_STDAFX_H__B0A9FE69_3B8B_11D3_9CFE_00400543FF49__INCLUDED_)
#import 指令简单地指向 ImagXpress ®控件,当你#import这个 ImagXpress控件时,编译器就会生成2个文件,分别是a .tli 和a .tlh文件,主要对控件的属性和方法创建必要的COM wrapper,由于该指令是在你的stdafx.h文件中,对于你其他的模块,这些wrapper也是随时可用的,wrapper的代码定义了COM的指针到你的.IDL-defined接口,用这个COM对象,你可以简单的创建一个接口实例,并在需要的时候直接调用方法,关闭这个示例的指针。

2、声明一个指向COM对象的指针

    添加完#import语句后,你需要定义一个指针指向ImagXpress的COM对象和它的事件处理器。我们已经实现了事件处理接口,这个借口位于安装在ImagXpress VC++\Include目录的ImagXpress12Events.h中。在文件中介绍了它封装的COM指针和事件处理程序接口的CImagXpress类,因此必须始终包含这个文件。在打印项目中,这个指针被称为pImagXpress,封装的类被称为ppCImagXpress,它们在PrintDlg.h文件中实现的方式如下所示:

// This code demonstrates how the pointer is declared and implemented in the PrintDlg.h file 
#if !defined(AFX_PRINTDLG_H__B0A9FE67_3B8B_11D3_9CFE_00400543FF49__INCLUDED_)
#define AFX_PRINTDLG_H__B0A9FE67_3B8B_11D3_9CFE_00400543FF49__INCLUDED_
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
Using namespace AccusoftImagXpress12;
#include " ImagXpress12Events.h "
/////////////////////////////////////////////////////////////////////////////
// CPrintDlg dialog
class CPrintDlg : public CDialog
public:
// Construction
CPrintDlg(CWnd* pParent = NULL); // standard constructor
// these are the pointers to our COM instance
CImagXpress *ppCImagXpress;
IImagXpressPtr pImagXpress;

3、初始化COM

在调用COM功能之前需要初始化COM库,此外,当你结束程序的时候,你也需要关闭COM库和删除ImagXpress COM对象,在Print.cpp文件中的说明如下所示:

// This code demonstrates how the COM library must be initialized 
BOOL CPrintApp::InitInstance()
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
CPrintDlg 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.
CoUnintialize();
//Since the dialog is closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;

4、创建 ImagXpress COM 对象

    需要创建 ImagXpress COM 对象的实例。创建对象后,可以使用该对象的属性和方法来集成ImagXpress的功能到你的应用程序中,在打印项目中,这个COM对象在PrintDlg.cpp文件中创建如下所示:

// This code demonstrates how the ImagXpress COM object is created 
BOOL CPrintDlg::OnInitDialog()
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
// 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
// Create an ImagXpress Object
ppCImagXpress = new CImagXpress(this, 1, m_hWnd, 50, 20, 50, 50);
pImagXpress = ppCImagXpress->pImagXpress;
// Control Initialization
if (pImagXpress)
pImagXpress->BorderType = BORD_Raised;
pImagXpress->FileName = "bird.jpg";
// From now on, the library is referenced by the new
// ImagXpress COM instance.
return TRUE; // return TRUE unless you set the focus to a control
}
// When creating a new ImagXpress object, you must pass the following parameters 
LPVOID classPtr
// The Dialog’s this pointer.
DWORD objID
// A unique object ID that you assign to the object’s instance. This ID can be used in event handling to determine which instance of an object has triggered the event.
long hWndParent
// The parent Window of the ImagXpress object. Typically, this is the Dialog’s hWnd.
long left
// The x coordinate of the ImagXpress object in pixels.
long top
// The top coordinate of the ImagXpress object in pixels.
long width
// The width of the ImagXpress object in pixels.
long height
// The height of the ImagXpress object in pixels.

5、删除 ImagXpress COM 对象

    当使用完这个ImagXpress对象后,你必须删除它,当对话框收到 WM_DESTROY 的消息时,就可以在适当的位置删除删除 ImagXpress COM 对象。

// This code demonstrates how to delete the ImagXpress COM object
void CPrintDlg::OnDestroy()
CDialog::OnDestroy();
if (pImagXpress)
pImagXpress = NULL;
if (ppCImagXpress)
delete ppCImagXpress;

>>>ImagXpress 下载


标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@pclwef.cn

文章转载自:慧都控件

为你推荐

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


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP