wxWidgets을 이용하여 프로그레스바를
생성하고 타이머를 이용해서 시간이 지남에 따라
프로그레스바가 변화하는 모습을 보여주는
예제 프로그램입니다.
개발환경
Gentoo Linux 2.6.32-r1
gcc 4.4.2
wxGTK 2.8.10
mainframe.h
mainframe.cpp
main.h
main.cpp
생성하고 타이머를 이용해서 시간이 지남에 따라
프로그레스바가 변화하는 모습을 보여주는
예제 프로그램입니다.
개발환경
Gentoo Linux 2.6.32-r1
gcc 4.4.2
wxGTK 2.8.10
mainframe.h
#ifndef _MAINFRAME_H_
#define _MAINFRAME_H_
#include<wx/wx.h>
#include<wx/string.h>
#include<wx/gauge.h>
#include<wx/timer.h>
const int ID_PROGRESSBAR = 101;
const int ID_TIMERID = 102;
class Mainframe : public wxFrame
{
private:
wxGauge *prgbar;
wxTimer *timer;
public:
int g_count;
Mainframe(const wxString& title);
//Timer 이벤트가 발생한 경우 호출되어질 핸들러
void OnTimer(wxTimerEvent &event);
};
#endif // _MAINFRAME_H_mainframe.cpp
#include "mainframe.h"
Mainframe::Mainframe(const wxString& title)
: wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(500, 200))
{
//box를 추가하기 위해서 panel을 생성
wxPanel *panel = new wxPanel(this, wxID_ANY);
//box 생성
// wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL);
//ProgressBar 생성
prgbar = new wxGauge(panel, ID_PROGRESSBAR, 100,
wxDefaultPosition, wxDefaultSize,
wxGA_SMOOTH, wxDefaultValidator, wxT(""));
//Timer 생성
timer = new wxTimer();
//Timer 이벤트가 발생할 경우 호출되어질 이벤트 핸들러 등록
Connect(ID_TIMERID, wxEVT_TIMER, wxTimerEventHandler(Mainframe::OnTimer));
//Timer의 Owner 설정
timer->SetOwner(this, ID_TIMERID);
//Timer 시작
timer->Start(100, wxTIMER_CONTINUOUS);
g_count = 0;
vbox->Add(prgbar, 1, wxEXPAND);
//panel에 box 추가
panel->SetSizer(vbox);
this->Centre();
}
void Mainframe::OnTimer(wxTimerEvent &event)
{
g_count = g_count + 10;
//ProgressBar의 값을 설정
prgbar->SetValue(g_count);
if(g_count == 100)
{
g_count = 0;
}
}main.h
#ifndef __MAIN_H_
#define __MAIN_H_
#include<wx/wx.h>
class FirstApp : public wxApp
{
public:
virtual bool OnInit();
};
#endif // __MAIN_H_main.cpp
#include "main.h"
#include "mainframe.h"
IMPLEMENT_APP(FirstApp)
bool FirstApp::OnInit()
{
Mainframe *main = new Mainframe(wxT("wxWidgets Example 15"));
main->Show(true);
return true;
}Posted by ExSuperstar





