OpenRS插件开发之自动生成菜单
2015-04-08 15:28
375 查看
平台:VC6.0;
目的:OpneRS上简单的自动生成菜单插件测试;
效果:(下图“My Test Menu”菜单)
说明:
在OpenRS上若欲把自己的某些需求(比如:匹配)做成插件,很多时候希望伴随程序启动能自动生成该插件自己的菜单,OpenRS也已经封装好了关于界面框架扩展的相应接口,可以满足这项自定义需求。亲测利用orsViewerExt_exeObject插件也可以添加自定义菜单,需新建个自己的接口,并修改相应代码,有兴趣的可以试下。个人感觉orsViewerExt_ROI插件独立简单的风格更合适,后面便主要以orsViewerExt_ROI插件为模板进行开发测试。本文也正是基于orsViewerExt_ROI做的测试Demo。
对于像我一样刚开始摸索的小白而言,《OpenRS软件集成方案与开发指南 - V0.85.doc》上面的说明或许还是看不太懂,所以只能笨笨地参照OpenRS自带的有类似功能的插件进行拆拆补补,并依葫芦画瓢。为了使需要的码友少走弯路、节省时间,更重要的是能快速走通这个流程,接下来步骤会尽量详细。
以下做法只是我尝试的一种思路,按需参考。
前期准备:
为方便日后文件管理(参看上篇博文《OpenRS插件开发新手上路》),为了进一步减少跟OpenRS目录的关联,我新建了个跟OpenRS目录平行的\OpenRSPro目录,并在\OpenRSRro\目录下建立自己的工作区目录,结构类似于OpenRS的组织结构。即,在\OpenRSRro\下新建一个文件夹desktop,在desktop目录下再分别新建三个文件夹build、include和src;在build目录下新建文件夹vc60,在src目录下新建文件夹plugins;在vc60目录下新建文件夹plugins。效果如下图所示。针对本例这已够用,以后可根据实际情况进行扩展,不多言。
方法流程:
(1) 打开VC6.0,新建一个MFC AppWizard [dll]工程,Project name设置为ext_Matching,Location设置为\OpenRSPro\desktop\build\vc60\plugins\目录,其他按默认设置,点击OK;选择”Regular
DLL using shared MFC DLL“(即默认的第二项),点击Finish,点击OK;
(2) 在File View视图中把工程下的文件全删掉,然后File -- Close Workspace;
(3) 在\OpenRSPro\desktop\src\plugins\目录下新建一个文件夹ext_Matching;
(4) 把\OpenRSPro\desktop\build\vc60\plugins\ext_Matching\目录下除”Debug“文件夹和"ext_Matching.dsp”外的所有文件(夹)剪切到步骤(3)新建的ext_Matching文件夹里;
(5) 到\OpenRSPro\desktop\src\plugins\ext_Matching目录下,将.clw、.def、.dsw、.ncb、.txt(共5个)文件删除;
(6) 将步骤(4)中的ext_Matching.dsp拖入到VC6.0中,Project -- Settings...;
(7) C/C++ -- Category -- Precompiled Headers,选择Automatic use of precompiled headers,并输入stdafx.h;
(8) C/C++ -- Category -- Preprocessor,在“Addtional include directories:"中输入”\openrs\external\include\BCGCBPro10.0,\openrs\desktop\include“;
(9) Link -- Category -- General,在”Output file name“中输入”\openRS\desktop\debug\vc60\Plugins\ext_Matching.dll“
(10) Link -- Category -- Input,在”Additional library path"中输入“\OpenRS\external\lib”,点击“OK“;
(11) Project -- Add To Project -- Files ,将\OpenRSPro\desktop\src\plugins\ext_Matching目录下的文件全部添加到工程中;
(12) File -- New -- C++ Source File,File名设为”orsXPlugin",Location设为“\OpenRSPro\desktop\src\plugins\ext_Matching”,点击OK;
(13) File -- New -- C/C++ Header File,File名设为”extXMatch",Location设为“\OpenRSPro\desktop\src\plugins\ext_Matching”,点击OK;
(14) File -- New -- C++ Source File,File名设为”extXMatch",Location设为“\OpenRSPro\desktop\src\plugins\ext_Matching”,点击OK;
(15) 打开Resource View视图(如果没有出现,可将鼠标放在视图和工作区中间那条竖直边界线上左右拖动下,便可出现)。
Insert -- Resource -- Menu,New。会自动生成一个“IDR_MENU1”
(16) 双击“IDR_MENU1”,在右侧添加菜单项,将Caption设为“Match Test”(自己起名就行)。若要继续添加菜单,不妨右键选择“View as Popup”;
(17) 打开StdAfx.h文件,在倒数第三行代码前一行添加一行代码:#include "BCGCBProInc.h";
(18) 打开ext_Matching.h文件,在后面添加一行代码:extern CExt_MatchingApp g_theApp;
(19) 打开ext_Matching.cpp文件,将最下面的”CExt_MatchingApp theApp“改为”CExt_MatchingApp g_theApp“ ;
(20) 打开orsXPlugin.cpp文件,将以下代码敲进去。
(21) 打开extXMatch.h文件,将以下代码敲进去:
(22) 打开extXMatch.cpp文件,将以下代码敲进去:
(23) 编译、链接。
(24) 运行OpenRS,去插件里查看;
(25) 去orsViewer里查看自动生成的菜单。
目的:OpneRS上简单的自动生成菜单插件测试;
效果:(下图“My Test Menu”菜单)
说明:
在OpenRS上若欲把自己的某些需求(比如:匹配)做成插件,很多时候希望伴随程序启动能自动生成该插件自己的菜单,OpenRS也已经封装好了关于界面框架扩展的相应接口,可以满足这项自定义需求。亲测利用orsViewerExt_exeObject插件也可以添加自定义菜单,需新建个自己的接口,并修改相应代码,有兴趣的可以试下。个人感觉orsViewerExt_ROI插件独立简单的风格更合适,后面便主要以orsViewerExt_ROI插件为模板进行开发测试。本文也正是基于orsViewerExt_ROI做的测试Demo。
对于像我一样刚开始摸索的小白而言,《OpenRS软件集成方案与开发指南 - V0.85.doc》上面的说明或许还是看不太懂,所以只能笨笨地参照OpenRS自带的有类似功能的插件进行拆拆补补,并依葫芦画瓢。为了使需要的码友少走弯路、节省时间,更重要的是能快速走通这个流程,接下来步骤会尽量详细。
以下做法只是我尝试的一种思路,按需参考。
前期准备:
为方便日后文件管理(参看上篇博文《OpenRS插件开发新手上路》),为了进一步减少跟OpenRS目录的关联,我新建了个跟OpenRS目录平行的\OpenRSPro目录,并在\OpenRSRro\目录下建立自己的工作区目录,结构类似于OpenRS的组织结构。即,在\OpenRSRro\下新建一个文件夹desktop,在desktop目录下再分别新建三个文件夹build、include和src;在build目录下新建文件夹vc60,在src目录下新建文件夹plugins;在vc60目录下新建文件夹plugins。效果如下图所示。针对本例这已够用,以后可根据实际情况进行扩展,不多言。
方法流程:
(1) 打开VC6.0,新建一个MFC AppWizard [dll]工程,Project name设置为ext_Matching,Location设置为\OpenRSPro\desktop\build\vc60\plugins\目录,其他按默认设置,点击OK;选择”Regular
DLL using shared MFC DLL“(即默认的第二项),点击Finish,点击OK;
(2) 在File View视图中把工程下的文件全删掉,然后File -- Close Workspace;
(3) 在\OpenRSPro\desktop\src\plugins\目录下新建一个文件夹ext_Matching;
(4) 把\OpenRSPro\desktop\build\vc60\plugins\ext_Matching\目录下除”Debug“文件夹和"ext_Matching.dsp”外的所有文件(夹)剪切到步骤(3)新建的ext_Matching文件夹里;
(5) 到\OpenRSPro\desktop\src\plugins\ext_Matching目录下,将.clw、.def、.dsw、.ncb、.txt(共5个)文件删除;
(6) 将步骤(4)中的ext_Matching.dsp拖入到VC6.0中,Project -- Settings...;
(7) C/C++ -- Category -- Precompiled Headers,选择Automatic use of precompiled headers,并输入stdafx.h;
(8) C/C++ -- Category -- Preprocessor,在“Addtional include directories:"中输入”\openrs\external\include\BCGCBPro10.0,\openrs\desktop\include“;
(9) Link -- Category -- General,在”Output file name“中输入”\openRS\desktop\debug\vc60\Plugins\ext_Matching.dll“
(10) Link -- Category -- Input,在”Additional library path"中输入“\OpenRS\external\lib”,点击“OK“;
(11) Project -- Add To Project -- Files ,将\OpenRSPro\desktop\src\plugins\ext_Matching目录下的文件全部添加到工程中;
(12) File -- New -- C++ Source File,File名设为”orsXPlugin",Location设为“\OpenRSPro\desktop\src\plugins\ext_Matching”,点击OK;
(13) File -- New -- C/C++ Header File,File名设为”extXMatch",Location设为“\OpenRSPro\desktop\src\plugins\ext_Matching”,点击OK;
(14) File -- New -- C++ Source File,File名设为”extXMatch",Location设为“\OpenRSPro\desktop\src\plugins\ext_Matching”,点击OK;
(15) 打开Resource View视图(如果没有出现,可将鼠标放在视图和工作区中间那条竖直边界线上左右拖动下,便可出现)。
Insert -- Resource -- Menu,New。会自动生成一个“IDR_MENU1”
(16) 双击“IDR_MENU1”,在右侧添加菜单项,将Caption设为“Match Test”(自己起名就行)。若要继续添加菜单,不妨右键选择“View as Popup”;
(17) 打开StdAfx.h文件,在倒数第三行代码前一行添加一行代码:#include "BCGCBProInc.h";
#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__B158965A_9C3F_4A58_874B_A6E908B52807__INCLUDED_)
(18) 打开ext_Matching.h文件,在后面添加一行代码:extern CExt_MatchingApp g_theApp;
//}}AFX_MSG DECLARE_MESSAGE_MAP() }; extern CExt_MatchingApp g_theApp; ///////////////////////////////////////////////////////////////////////////// //{{AFX_INSERT_LOCATION}} // Microsoft Visual C++ will insert additional declarations immediately before the previous line. #endif // !defined(AFX_EXT_MATCHING_H__878828EE_FC92_430D_9AF9_8F6AEAD942D0__INCLUDED_)
(19) 打开ext_Matching.cpp文件,将最下面的”CExt_MatchingApp theApp“改为”CExt_MatchingApp g_theApp“ ;
(20) 打开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 )
(21) 打开extXMatch.h文件,将以下代码敲进去:
#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_
(22) 打开extXMatch.cpp文件,将以下代码敲进去:
#include "stdafx.h" #include "ext_Matching.h" #include "extXMatch.h" 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; }
(23) 编译、链接。
(24) 运行OpenRS,去插件里查看;
(25) 去orsViewer里查看自动生成的菜单。
相关文章推荐
- IDEA插件开发初体验之(GET/SET自动生成带模版注释插件的开发与使用)
- Maven自定义插件开发(rapid-generator自动生成代码)
- Visual Studio Package 插件开发之自动生成实体工具
- (开发笔记)转载:eclipse maven 插件 自动生成mybatis dao、mapper
- android studio 插件开发(自动生成框架代码插件)
- 基于注解处理器开发自动生成getter和setter方法的插件
- [置顶] AS插件开发:根据特定格式的文本自动生成Java Bean文件或字段
- [jQuery插件开发][dynamicTable2.0]根据JSON数据自动生成HTML Table
- eclipse maven 搭建 SSM(Spring+SpringMVC+MyBatis)开发环境 和 MyBatis 自动生成的 maven 插件配置
- 从数据库自动生成菜单
- [C#]一步一步开发自己的自动代码生成工具之一:获取SQL2005的数据库表结构
- 自动生成你的程序开发文档
- [C#]一步一步开发自己的自动代码生成工具之二:SQLServer字段与C#变量的对应转化
- 一款vs2005自动生成getter/setter插件:VSPropertyGenerator2
- Ruby on rails开发从头来(windows)(十八)-自动生成文档
- [C#]一步一步开发自己的自动代码生成工具之六:业务层模板
- 一个spring+hibernate开发的小程序的修改(其中配置文件使用的是HibernateSynchronizer插件生成)
- Java Web开发中可否自动生成结构一致的代码?
- [C#]一步一步开发自己的自动代码生成工具之四:简单三层代码模板实例Model层
- 【转载】自动生成CSS菜单的软件