wxWidgets结合firebreath开发插件
1、 编译wxWidget的时候,property->configuration Properties->c/c++->CodeGeneration->Runtime Library一项设置为Multi-threaded Debug(/MTd),因为firebreath生成的工程的这一项均是Multi-threaded Debug(/MTd)。如果不一致会出错。
错误如:
>msvcprtd.lib(MSVCP90D.dll): error LNK2005: "public: class std::basic_string<char,structstd::char_traits<char>,class std::allocator<char> > &__thiscall std::basic_string<char,struct std::char_traits<char>,classstd::allocator<char> >::operator=(char const *)"(??4?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV01@PBD@Z)already defined in libcpmtd.lib(locale0.obj)。
>MSVCRTD.lib(MSVCR90D.dll): error LNK2005: _tolower already defined in LIBCMTD.lib(tolower.obj)等。
如果wxWidget编译的时候RuntimeLibrary这一项设置的是Multi-threadedDebug DLL(/MDd),则在wxWidgets结合firebreath后的工程,每个子工程的RuntimeLibrary这一项全部改成Multi-threadedDebug DLL(/MDd)。
2、 如果你使用了unicode参数,你必须在setup.h(这个文件通常在C:\wxWidgets-2.9.2\lib\vc_lib\mswud\wx)这个文件中定义
#define wxUSE_UNICODE 1
3、 你必须在使用到wxWidget的相关的类的xx.cpp中添加下面这一行
#pragmacomment(lib, "comctl32.lib")
4、 你需要在工程属性
configuration Properties->Linker->Input->AdditionalDependencids这一项中添加下面这些库:
kernel32.lib
user32.lib
gdi32.lib
winspool.lib
shell32.lib
ole32.lib
oleaut32.lib
uuid.lib
comdlg32.lib
advapi32.lib
psapi.lib
..\..\ActiveXCore\Debug\ActiveXCore.lib
..\..\PluginCore\Debug\PluginCore.lib
PluginAuto\Debug\NBP_PluginAuto.lib
..\..\NpapiCore\Debug\NpapiCore.lib
..\..\ScriptingCore\Debug\ScriptingCore.lib
..\..\boost\libs\thread\Debug\boost_thread.lib
..\..\boost\libs\system\Debug\boost_system.lib
Wininet.lib
oleacc.lib
wxmsw28ud_core.lib
wxbase28ud.lib
rpcrt4.lib
winmm.lib
wsock32.lib
5、 在Tools->Options->Projects andSolutions->VC++ Project Settings->show directories for:->Include files里添加\wxWidgets-2.9.2\include和\wxWidgets-2.9.2\include\msvc;在show directories for:->Libraryfiles中添加\wxWidgets-2.9.2\lib\vc_lib。
加上这些之后可不必在工程的Cmakelists文件中添加wxWidgets的任何相关的语句。
6、 firebreath与wxWidget结合处的主要代码框架为下面,主要修改的是NGHBrowserPlugin.cpp这个文件。
// For compilers that support precompilation,includes "wx/wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#include "wx/app.h"
#include "wx/mdi.h"
#include "wx/docview.h"
#include "wx/docmdi.h"
#include "wx/defs.h"
#include "wx/app.h"
#include "wx/menu.h"
#include "wx/dcclient.h"
#include "wx/wfstream.h"
#if wxUSE_ZLIB
#include "wx/zstream.h"
#endif
// Define a new application
class MyApp: public wxApp
{
public:
MyApp(void);
bool OnInit(void) { return true; }
int OnExit(void) { return 0; };
// This is the replacement for the normal main(): all program work should
// be done here. When OnRun() returns, the programs starts shutting down.
virtual int OnRun()
{
return 0;
}
protected:
wxDocManager* m_docManager;
};
DECLARE_APP(MyApp)
IMPLEMENT_APP(MyApp)
//IMPLEMENT_APP_NO_MAIN(MyApp)
MyApp::MyApp(void)
{
m_docManager = (wxDocManager *) NULL;
}
// .. some firebreath generated codes..
bool NGHBrowserPlugin::onWindowAttached(FB::AttachedEvent *evt,FB::PluginWindow * winWin)
{
MyApp* pApp = new MyApp();
wxAppConsole::SetInstance(pApp);
int argc = 0;
pApp->Initialize(argc, NULL);
wxWindow* win = new wxWindow();
if(win)
{
FB::PluginWindowWin* w = (FB::PluginWindowWin*)(winWin);
win->AssociateHandle(w->getHWND());
if(win)
{
TestGLCanvas* pCtrl = new TestGLCanvas(win, 1000);
mCanvas = pCtrl;
FB::Rect rc = winWin->getWindowPosition();
pCtrl->Move(1, 1);
pCtrl->SetSize(wxSize(rc.right - rc.left, rc.bottom - rc.top));
pCtrl->Show(true);
pCtrl->LoadDXF(wxT("penguin.dxf"));
w->InvalidateWindow();
}
}
// The window is attached; act appropriately
return false;
}