当前位置:编程学习 > 网站相关 >>

[wxWidgets]_[简单应用看wx的核心原理]

 

 

 

1.wx的核心原理和MFC差不多,其中的一部分是menu,event,thread,dc,control.

2.以下是使用和wx这些功能的例子,在MinGW(g++),msys(make)下编译.g++ 4.4,我用的eclipse CDT建的工程,单是编译的话直接用make就行了,不需要eclipse.


3.用的wxWidgets-2.9.2,核心的dll只需要3个,由于是编译了基本上全部功能和控件,所以这些库还是比较大的,不过有很大的压缩余地。也和gcc编译有关。


[plain]
wxbase292u_gcc_custom.dll (6,461 kb) 
wxmsw292u_adv_gcc_custom.dll (5,498 kb) 
wxmsw292u_core_gcc_custom.dll (12,237 kb) 

wxbase292u_gcc_custom.dll (6,461 kb)
wxmsw292u_adv_gcc_custom.dll (5,498 kb)
wxmsw292u_core_gcc_custom.dll (12,237 kb)
4.应用程序入口文件:

my_app.h


[cpp]
/*
 * my_app.h
 *
 *  Created on: 2013-5-30
 *  Author: Sai
 */ 
 
#ifndef MY_APP_H_  
#define MY_APP_H_  
 
#include "wx/wx.h"  
 
class MyApp: public wxApp 

public: 
    MyApp(); 
    virtual ~MyApp(); 
 
    bool OnInit(); 
}; 
 
#endif /* MY_APP_H_ */ 

/*
 * my_app.h
 *
 *  Created on: 2013-5-30
 *  Author: Sai
 */

#ifndef MY_APP_H_
#define MY_APP_H_

#include "wx/wx.h"

class MyApp: public wxApp
{
public:
 MyApp();
 virtual ~MyApp();

 bool OnInit();
};

#endif /* MY_APP_H_ */

 

my_app.cpp


[cpp]
*
 * my_app.cpp
 *
 *  Created on: 2013-5-30
 *  Author: Sai
 */ 
 
#include "my_app.h"  
#include "my_frame.h"  
 
IMPLEMENT_APP(MyApp) 
 
MyApp::MyApp() 

 

 
MyApp::~MyApp() 

 

 
bool MyApp::OnInit() 

    MyFrame* frame = new MyFrame(); 
    frame->Create(wxID_ANY,wxT("infoworld")); 
 
    SetTopWindow(frame); 
    frame->Show(true); 
    return true; 

/*
 * my_app.cpp
 *
 *  Created on: 2013-5-30
 *  Author: Sai
 */

#include "my_app.h"
#include "my_frame.h"

IMPLEMENT_APP(MyApp)

MyApp::MyApp()
{

}

MyApp::~MyApp()
{

}

bool MyApp::OnInit()
{
 MyFrame* frame = new MyFrame();
 frame->Create(wxID_ANY,wxT("infoworld"));

 SetTopWindow(frame);
 frame->Show(true);
 return true;
}


5.主窗口文件

my_frame.h


[cpp]
/*
 * my_frame.h
 *
 *  Created on: 2013-5-30
 *  Author: Sai
 */ 
 
#ifndef MY_FRAME_H_  
#define MY_FRAME_H_  
 
#include "wx/wx.h"  
 
/**
 * Show Example
 *
 * 1.menu
 * 2.event
 * 3.thread
 * 4.dc
 * 5.control
 */ 
class MyFrame : public wxFrame 

    DECLARE_EVENT_TABLE() 
    DECLARE_DYNAMIC_CLASS(MyFrame) 
public: 
    MyFrame(); 
    virtual ~MyFrame(); 
    virtual bool Create(wxWindowID id, const wxString& title); 
 
protected: 
    void OnQuit(wxCommandEvent& event); 
    void OnThread(wxCommandEvent& event); 
    void OnThreadUpdate(wxThreadEvent& event); 
    void OnPaintPanel(wxPaintEvent& event); 
private: 
    wxGauge* gauge_; 
    wxPanel *panel_; 
}; 
 
#endif /* MY_FRAME_H_ */ 

/*
 * my_frame.h
 *
 *  Created on: 2013-5-30
 *  Author: Sai
 */

#ifndef MY_FRAME_H_
#define MY_FRAME_H_

#include "wx/wx.h"

/**
 * Show Example
 *
 * 1.menu
 * 2.event
 * 3.thread
 * 4.dc
 * 5.control
 */
class MyFrame : public wxFrame
{
 DECLARE_EVENT_TABLE()
 DECLARE_DYNAMIC_CLASS(MyFrame)
public:
 MyFrame();
 virtual ~MyFrame();
 virtual bool Create(wxWindowID id, const wxString& title);

protected:
 void OnQuit(wxCommandEvent& event);
 void OnThread(wxCommandEvent& event);
 void OnThreadUpdate(wxThreadEvent& event);
 void OnPaintPanel(wxPaintEvent& event);
private:
 wxGauge* gauge_;
 wxPanel *panel_;
};

#endif /* MY_FRAME_H_ */

my_frame.cpp


[cpp]
*
 * my_frame.cpp
 *
 *  Created on: 2013-5-30
 *  Author: Sai
 */ 
 
#include "my_frame.h"  
 
namespace 

enum 

    kGauge = 1, kButton, kThreadUpdateId 
}; 

 
class MyThread: public wxThread 

public: 
    MyThread(MyFrame *handler) : 
            wxThread(wxTHREAD_DETACHED) 
    { 
        m_pHandler = handler; 
    } 
    ~MyThread() 
    { 
    } 
    void Execute() 
    { 
        Create(); 
        Run(); 
    } 
 
protected: 
    virtual ExitCode Entry() 
    { 
        for (int i = 1; i < 11; ++i) 
        { 
            //1.asynchronous update,communicate with main thread.  
            wxThreadEvent* event = new wxThreadEvent(wxEVT_THREAD, 
                    kThreadUpdateId); 
            event->SetInt(i * 10); 
            wxQueueEvent(m_pHandler->GetEventHandler(), event); 
        } 
        return (wxThread::ExitCode) 0; 
    } 
  &nb

补充:综合编程 , 其他综合 ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,