天天看點

關于AUI、wxPropertyGrid及wxGrid的用法示例

本執行個體完整包見我的下載下傳資源中的auidemo。

注意:需要編譯propgrid為庫檔案并放進工程中。

#include "auidemoMain.h"

#include <wx/msgdlg.h>

#include <wx/textctrl.h>

#include <wx/grid.h>

#include "wx/aui/aui.h"

// Main propertygrid header.

#include <wx/propgrid/propgrid.h>

#include "treelistctrl.h"

// Needed for implementing custom properties.

#include <wx/propgrid/propdev.h>

// Extra property classes.

#include <wx/propgrid/advprops.h>

// This defines wxPropertyGridManager.

#include <wx/propgrid/manager.h>

// XRC-handler (note that the source portion has to be added separately in the project)

#include <wx/propgrid/xh_propgrid.h>

//(*InternalHeaders(auidemoFrame)

#include <wx/intl.h>

#include <wx/string.h>

//*)

//helper functions

enum wxbuildinfoformat

{

    short_f, long_f

};

wxString wxbuildinfo(wxbuildinfoformat format)

{

    wxString wxbuild(wxVERSION_STRING);

    if (format == long_f )

    {

#if defined(__WXMSW__)

        wxbuild << _T("-Windows");

#elif defined(__UNIX__)

        wxbuild << _T("-Linux");

#endif

#if wxUSE_UNICODE

        wxbuild << _T("-Unicode build");

#else

        wxbuild << _T("-ANSI build");

#endif // wxUSE_UNICODE

    }

    return wxbuild;

}

//(*IdInit(auidemoFrame)

const long auidemoFrame::idMenuQuit = wxNewId();

const long auidemoFrame::idMenuAbout = wxNewId();

const long auidemoFrame::ID_STATUSBAR1 = wxNewId();

//*)

BEGIN_EVENT_TABLE(auidemoFrame,wxFrame)

    //(*EventTable(auidemoFrame)

    //*)

END_EVENT_TABLE()

auidemoFrame::auidemoFrame(wxWindow* parent,wxWindowID id)

{

    //(*Initialize(auidemoFrame)

    wxMenuItem* MenuItem2;

    wxMenuItem* MenuItem1;

    wxMenu* Menu1;

    wxMenuBar* MenuBar1;

    wxMenu* Menu2;

    m_auiManage.SetManagedWindow(this);

    Create(parent, id, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, _T("id"));

    MenuBar1 = new wxMenuBar();

    Menu1 = new wxMenu();

    MenuItem1 = new wxMenuItem(Menu1, idMenuQuit, _("Quit/tAlt-F4"), _("Quit the application"), wxITEM_NORMAL);

    Menu1->Append(MenuItem1);

    MenuBar1->Append(Menu1, _("&File"));

    Menu2 = new wxMenu();

    MenuItem2 = new wxMenuItem(Menu2, idMenuAbout, _("About/tF1"), _("Show info about this application"), wxITEM_NORMAL);

    int i, j;

    for (j=0; j<10 ; j++)

        i=j*j;

    Menu2->Append(MenuItem2);

    MenuBar1->Append(Menu2, _("Help"));

    SetMenuBar(MenuBar1);

    StatusBar1 = new wxStatusBar(this, ID_STATUSBAR1, 0, _T("ID_STATUSBAR1"));

    int __wxStatusBarWidths_1[1] = { -1 };

    int __wxStatusBarStyles_1[1] = { wxSB_NORMAL };

    StatusBar1->SetFieldsCount(1,__wxStatusBarWidths_1);

    StatusBar1->SetStatusStyles(1,__wxStatusBarStyles_1);

    SetStatusBar(StatusBar1);

    wxTextCtrl* text = new wxTextCtrl(this, -1);

    wxGrid* grid = new wxGrid();

    grid->Create(this,-1);

    grid->CreateGrid(10000,60);

    m_propGrid = new wxPropertyGrid(

        this, // parent

        -1, // id

        wxDefaultPosition, // position

        wxDefaultSize, // size

        // Some specific window styles - for all additional styles,

        // see Modules->PropertyGrid Window Styles

        wxPG_AUTO_SORT | // Automatic sorting after items added

        wxPG_SPLITTER_AUTO_CENTER | // Automatically center splitter until user manually adjusts it

        // Default style

        wxPG_DEFAULT_STYLE );

    // Add int property

    m_propGrid->Append( new wxIntProperty(wxT("IntProperty"), wxPG_LABEL, 12345678) );

    // Add float property (value type is actually double)

    m_propGrid->Append( new wxFloatProperty(wxT("FloatProperty"), wxPG_LABEL, 12345.678) );

    // Add a bool property

    m_propGrid->Append( new wxBoolProperty(wxT("BoolProperty"), wxPG_LABEL, false) );

    m_auiManage.AddPane(text, wxLEFT, wxT("我的指令行視窗"));

    m_auiManage.AddPane(m_propGrid, wxLEFT, wxT("我的屬性"));

    m_auiManage.AddPane(grid, wxCENTER, wxT("統計表"));

    m_auiManage.Update();

    Connect(idMenuQuit,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&auidemoFrame::OnQuit);

    Connect(idMenuAbout,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&auidemoFrame::OnAbout);

    //*)

}

auidemoFrame::~auidemoFrame()

{

    //(*Destroy(auidemoFrame)

    //*)

    m_auiManage.UnInit();

}

void auidemoFrame::OnQuit(wxCommandEvent& event)

{

    Close();

}

void auidemoFrame::OnAbout(wxCommandEvent& event)

{

    wxString msg = wxbuildinfo(long_f);

    wxMessageBox(msg, _("Welcome to..."));

}