1. 在OpenRS目录下新建文件夹shell,用于存放添加的项目,名字可以随意;
2. 在VS2013下新建项目ext_Matching
3. 项目属性设置
项目属性-》配置属性-》常规,包括输出目录、中间目录和配置类型设置
项目属性-》配置属性-》VC++目录,包括包含目录和库目录
包含目录添加
D:\OpenRS\external\include\BCGCBPro22.1
D:\OpenRS\desktop\include
库目录添加D:\OpenRS\external\lib
项目属性-》配置属性-》链接器,设置输出文件
输出文件\openRS\desktop\debug\vc60\Plugins\ext_Matching.dll
4. 头文件、源文件、资源文件编写
资源文件
在解决方案视图中,在”资源文件”右键-添加-资源-Menu-新建
编辑菜单
注意:添加资源后自动生成“resource.h”
头文件
StdAfx.h
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#if !defined(AFX_STDAFX_H__B191D6A9_6437_4DC2_85D3_D4A09AC05E69__INCLUDED_)
#define AFX_STDAFX_H__B191D6A9_6437_4DC2_85D3_D4A09AC05E69__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
#ifndef _AFX_NO_OLE_SUPPORT
#include <afxole.h> // MFC OLE classes
#include <afxodlgs.h> // MFC OLE dialog classes
#include <afxdisp.h> // MFC Automation classes
#endif // _AFX_NO_OLE_SUPPORT
#ifndef _AFX_NO_DB_SUPPORT
#include <afxdb.h>// MFC ODBC database classes
#endif // _AFX_NO_DB_SUPPORT
#ifndef _AFX_NO_DAO_SUPPORT
#include <afxdao.h>// MFC DAO database classes
#endif // _AFX_NO_DAO_SUPPORT
#include <afxdtctl.h>// MFC support for Internet Explorer 4 Common Controls
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h>// MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT
#include <BCGCBProInc.h>
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_STDAFX_H__B191D6A9_6437_4DC2_85D3_D4A09AC05E69__INCLUDED_)
头文件extXMatch.h
#ifndef __AFXWIN_H__
#error include 'stdafx.h' before including this file for PCH
#endif
#include "resource.h"// main symbols
class CExt_MatchingApp : public CWinApp
{
public:
CExt_MatchingApp(){};
DECLARE_MESSAGE_MAP()
};
extern CExt_MatchingApp g_theApp;
#ifndef _ORS_VIEWER_EXTENSION_MATCHING_H_
#define _ORS_VIEWER_EXTENSION_MATCHING_H_
#include "orsGuiBase/orsIGuiElement.h"
#include "orsGuiBase/orsIViewerExtension.h"
interface extXMatch : public orsIViewerExtension, public orsObjectBase
{
public:
extXMatch();
~extXMatch();
// SetLayerCollection、SetImageViewer是实现orsIViewerExtension接口必须要实现的成员函数
virtual void SetLayerCollection(orsILayerCollection *pLayerCollection);
virtual void SetImageViewer(orsIImageView *pImageViewer);
// create、pluginMenu、windowProc、OnCmdMsg是实现orsIGuiExtension接口必须要实现的成员函数
virtual bool create(orsIFrameWnd *frameWnd);
virtual bool pluginMenu(orsIFrameWnd *frameWnd);
virtual LRESULT windowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
virtual BOOL OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo);
public:
orsILayerCollection *GetLayerCollection(){ return m_pLayerCollection; };
public:
orsIFrameWnd *m_pParentFrameWnd;
orsILayerCollection *m_pLayerCollection;
orsIImageView *m_pImageViewer;
public:
ORS_OBJECT_IMP2(extXMatch, orsIViewerExtension, orsIGuiExtension, "matching", "orsViewer Extension - Matching")
};
#endif // _ORS_VIEWER_EXTENSION_MATCHING_H_
源文件
extXMatch.cpp
#include "stdafx.h"
#include "extXMatch.h"
#include "resource.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
BEGIN_MESSAGE_MAP(CExt_MatchingApp, CWinApp)
END_MESSAGE_MAP()
CExt_MatchingApp g_theApp;
extXMatch::extXMatch()
{
m_pParentFrameWnd = NULL;
m_pLayerCollection = NULL;
m_pImageViewer = NULL;
}
extXMatch::~extXMatch()
{
}
bool extXMatch::create(orsIFrameWnd *frameWnd)
{
HINSTANCE oldRcHandle = AfxGetResourceHandle();
AfxSetResourceHandle(GetModuleHandle("ext_Matching.dll"));
//
m_pParentFrameWnd = frameWnd;
frameWnd->AddMenu(&g_theApp, IDR_MENU1, _T("My Test Menu"), _T("帮助"));
//
AfxSetResourceHandle(oldRcHandle);
return true;
}
void extXMatch::SetLayerCollection(orsILayerCollection *pLayerCollection)
{
m_pLayerCollection = pLayerCollection;
}
void extXMatch::SetImageViewer(orsIImageView *pImageViewer)
{
m_pImageViewer = pImageViewer;
}
LRESULT extXMatch::windowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
return AfxGetAfxWndProc()(hWnd, message, wParam, lParam);
return FALSE;
}
BOOL extXMatch::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
{
if (g_theApp.OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
return TRUE;
return FALSE;
}
//
bool extXMatch::pluginMenu(orsIFrameWnd *frameWnd)
{
HINSTANCE oldRcHandle = AfxGetResourceHandle();
AfxSetResourceHandle(GetModuleHandle("ext_Matching.dll"));
frameWnd->AddMenu(&g_theApp, IDR_MENU1, _T("My Test Menu"), _T("帮助"));
//
AfxSetResourceHandle(oldRcHandle);
return true;
}
orsXPlugin.cpp
#include "stdafx.h"
#include "orsBase/orsIPlatform.h"
#include "extXMatch.h"
//
extXMatch *g_orsExtXMatch = NULL;
orsIObject* createExtXMatch(bool bForRegister)
{
if (bForRegister)
return new extXMatch;
else {
g_orsExtXMatch = new extXMatch;
return g_orsExtXMatch;
}
}
//
class orsXPlugin : public orsIPlugin
{
public:
virtual const orsChar *getID()
{
return "org.openRS.ext_Matching";
};
virtual const orsChar *getName()
{
return "ext_Matching";
};
virtual const orsChar *getProvider()
{
return "edu.whu.rs";
};
virtual const orsChar *getVersion()
{
return "0.1";
}
virtual bool initialize(orsIPlatform* platform)
{
orsIRegisterService *pRegister = platform->getRegisterService();
pRegister->registerObject(createExtXMatch);
return true;
}
virtual void finalize()
{
}
};
ORS_REGISTER_PLUGIN(orsXPlugin)
5. 编译、链接。
6. 运行OpenRS,去插件里查看;
7. 去orsViewer里查看自动生成的菜单。
注:参考来源http://blog.csdn.net/zshuaihua/article/details/44941467,原文章基于VC++6.0进行,现在在VS2013下实践了