level 3
//simple.h
#pragma once
#include<wx/wx.h>
class Simple:public wxFrame
{
public:
Simple(const wxString& title);
};
//simple.cpp
#include "Simple.h"
#include"MyStatusBar.h"
Simple::Simple(const wxString& title) :wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(450,300))
{
MyStatusBar* statusBar = new MyStatusBar(this, wxID_ANY);
statusBar->setGaugeValue(10);
this->SetStatusBar(statusBar);
this->Centre();
}
//myStatusBar.h
#pragma once
#include<wx/wx.h>
class MyStatusBar:public wxStatusBar
{
public:
MyStatusBar(wxWindow *parent,wxWindowID id = wxID_ANY,long style = wxSTB_DEFAULT_STYLE,const wxString& name = wxStatusBarNameStr);
void setGaugeValue(int n);
int getGaugeValue();
private:
void OnSize(wxSizeEvent& event);
wxGauge* gauge;
int gaugeRange = 100;
};
//myStatusBar.cpp
#include "MyStatusBar.h"
MyStatusBar::MyStatusBar(wxWindow *parent, wxWindowID id /*= wxID_ANY*/, long style /*= wxSTB_DEFAULT_STYLE*/, const wxString& name /*= wxStatusBarNameStr*/)
:wxStatusBar(parent,id,style,name)
{
this->SetFieldsCount(3);
int patch[3] = { -1, -1,100 };//窗口将分成三段:其中第3段是固定宽度100pix,第1段和第2段动态1:1比例分配宽度。
this->SetStatusWidths(3, patch);
this->gauge = new wxGauge(this, -1, gaugeRange);
this->Bind(wxEVT_SIZE, &MyStatusBar::OnSize, this);
}
void MyStatusBar::setGaugeValue(int n)
{
if ((n >= 0 && n <= gaugeRange))
{
this->gauge->SetValue(n);
}
}
int MyStatusBar::getGaugeValue()
{
return this->gauge->GetValue();
}
void MyStatusBar::OnSize(wxSizeEvent& event)
{
wxRect rect;
this->GetFieldRect(2, rect);//获取第3段的位置信息;
this->gauge->SetPosition(wxPoint(rect.x + 1, rect.y + 1));
this->gauge->SetSize(wxSize(rect.width - 4, rect.height - 4));
}
2016年04月20日 01点04分
