一、simpletoolbars.h
#include <wx/wxprec.h>
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif // WX_PRECOMP
class SimpleToolbars:public wxFrame
{
public:
SimpleToolbars(const wxString& title);
protected:
void OnQuit(wxCommandEvent& event);
wxToolBar *toolbar1;
wxToolBar *toolbar2;
};
二、simpletoolbars.cpp
#include "simpletoolbars.h"
SimpleToolbars::SimpleToolbars(const wxString& title)
:wxFrame(NULL,wxID_ANY,title,wxDefaultPosition,wxSize(280,180))
{
wxImage::AddHandler(new wxPNGHandler);
wxBitmap exit("exit.png",wxBITMAP_TYPE_PNG);
wxBitmap newb("new.png",wxBITMAP_TYPE_PNG);
wxBitmap open("open.png",wxBITMAP_TYPE_PNG);
wxBitmap save("save.png",wxBITMAP_TYPE_PNG);
wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL);
toolbar1= new wxToolBar(this,wxID_ANY,wxDefaultPosition,wxDefaultSize
,wxTB_TEXT);
toolbar1->AddTool(wxID_NEW,"New",newb);
toolbar1->AddTool(wxID_OPEN,"Open",open);
toolbar1->AddTool(wxID_SAVE,"Save",save);
toolbar1->Realize();
toolbar2= new wxToolBar(this,wxID_ANY);
toolbar2->AddTool(wxID_EXIT,"quit",exit);
toolbar2->Realize();
vbox->Add(toolbar1,0,wxEXPAND);
vbox->Add(toolbar2,0,wxEXPAND);
SetSizer(vbox);
Bind(wxEVT_COMMAND_TOOL_CLICKED,SimpleToolbars::OnQuit,this,wxID_EXIT);
this->Centre();
}
void SimpleToolbars::OnQuit(wxCommandEvent& event)
{
Close(true);
}