正文

1.wxWidgets初步 (手把手有限元编程)2007-06-17 23:36:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/oopfem/26866.html

分享到:

手把手有限元编程系列,给大家讲解如何利用c++语言,借助wxWidgets和opengl构建有限元程序.... 第一篇, wxWidgets初步 开发交互软件首先必须有界面, wxWidgets是很不错的界面库,由于wxWidgets的教材很少,所以本篇先介绍如何分离wxWidgets基本框架的几个类, 首先,MVApp类是主应用程序类, /***********************MVApp.h************************/#ifndef MV_APP_H#define MV_APP_H#pragma warning (disable: 4018)#include "wx_pch.h"#include "MVFrame.h"class MVApp: public wxApp{public:    bool OnInit(); MVFrame * GetFrame(void);private: MVFrame * frame;};DECLARE_APP(MVApp);#endif // #ifndef MV_APP_H /*************************************MVApp.cpp**************************************/#include "MVApp.h"IMPLEMENT_APP(MVApp)//Main program (equivalent)bool MVApp::OnInit(){    // Create the main frame window    frame = new MVFrame(NULL, wxT("MV Post"),wxDefaultPosition, wxSize(650, 600));    // Show the frame     frame->Show(true);    return true;}MVFrame * MVApp::GetFrame(void){ return frame;} MVFrame是主框架类,负责界面的构建, /*************************************MVFrame.h**************************************/#ifndef MV_FRAME_H#define MV_FRAME_H#pragma warning (disable: 4018)#include "wx_pch.h"class MVFrame: public wxFrame{public:    MVFrame(wxFrame *frame, const wxString& title, const wxPoint& pos,            const wxSize& size, long style = wxDEFAULT_FRAME_STYLE); void OnExit       (wxCommandEvent& WXUNUSED(event)) { Close(true); } void OnAbout      (wxCommandEvent& WXUNUSED(event)); private:    DECLARE_EVENT_TABLE()};#endif // #ifndef MV_FRAME_H /*****************************************MVFrame.cpp******************************************/#include "MVFrame.h"BEGIN_EVENT_TABLE(MVFrame, wxFrame) EVT_MENU(wxID_EXIT, MVFrame::OnExit) EVT_MENU(ID_ABOUT, MVFrame::OnAbout)END_EVENT_TABLE()/* My frame constructor */MVFrame::MVFrame(wxFrame *frame, const wxString& title, const wxPoint& pos,    const wxSize& size, long style)    : wxFrame(frame, wxID_ANY, title, pos, size, style){        CreateMenubar();     // Create a statubar  CreateStatusBar(2); SetStatusText(wxT("MyFEM"),0); } void MVFrame::CreateMenubar(){    wxMenuBar *menuBar = new wxMenuBar;     wxMenu *winMenu = new wxMenu;    winMenu->Append(wxID_EXIT, wxT("E&xit"));    menuBar->Append(winMenu, wxT("&File"));     winMenu = new wxMenu;    winMenu->Append(ID_ABOUT, _T("About..."));    menuBar->Append(winMenu, _T("&Help"));     SetMenuBar(menuBar);} /* Intercept menu commands */ void MVFrame::OnAbout(wxCommandEvent& WXUNUSED(event)){    (void)wxMessageBox(_T("About MVPost"));} 另外,头文件wx_pch.h里面设置基本的wxWidgets链接, /***************************************wx_pch.h****************************************/#ifndef WX_PCH_H_INCLUDED#define WX_PCH_H_INCLUDED #if ( defined(USE_PCH) && !defined(WX_PRECOMP) )#define WX_PRECOMP#endif // USE_PCH // basic wxWidgets headers#include <wx/wxprec.h> // for use xrc files#include <wx/xrc/xmlres.h> #ifdef __BORLANDC__#pragma hdrstop#endif #ifndef WX_PRECOMP#include <wx/wx.h>#endif #if !wxUSE_GLCANVAS    #error "OpenGL required: set wxUSE_GLCANVAS to 1 and rebuild the library"#endif #ifdef USE_PCH// put here all your rarely-changing header files #endif // USE_PCH #endif // WX_PCH_H_INCLUDED 将以上5个文件添加到设置好wxWidgets环境的VC工程中,即可生成漂亮的程序界面, 在此基础上就可以开始添加有限元类了, 生成程序如下:  

阅读(15844) | 评论(5)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

loading...
您需要登录后才能评论,请 登录 或者 注册