您的位置:首页 > 产品设计 > UI/UE

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

2010-02-20 17:10 447 查看
本实例完整包见我的下载资源中的auidemo。

注意:需要编译propgrid为库文件并放进工程中。

/***************************************************************
* Name: auidemoMain.cpp
* Purpose: Code for Application Frame
* Author: Yavobo (Yavobo@163.com)
* Created: 2010-02-18
* Copyright: Yavobo (http://www.mymanager.com/)
* License:
**************************************************************/

#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..."));
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: