[wxWidgets] 15. 프로그래스바 및 타이머 제어
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
Track this back : http://exsuperstar.net/trackback.php?blogid=408
Commented by
임승욱
at 2010/02/08/ 21:03
오 감사 합니다
혹시나 해서 들려 봤는데^^
혹시나 해서 들려 봤는데^^
Commented by
임승욱
at 2010/02/09/ 01:16
public :
void GaugeTimer(wxTimerEvent &event);
const int ID_TEST_GAUGETIME = 100;
EVT_TIMER(ID_TEST_GAUGETIME,MyFrame::GaugeTimer)
//ProgressBar 생성
prgbar = new wxGauge(panel, ID_PROGRESSBAR, 500,wxPoint(40,10), wxSize(200,20),
wxGA_SMOOTH, wxDefaultValidator, wxT(""));
//Timer 생성
m_GaugeTimer = new wxTimer(this,ID_TEST_GAUGETIME);
이렇게 하니까 boxsizer에 올리지 않아도 되고, wxpoint 에 맞게 출력에 되더군요
void GaugeTimer(wxTimerEvent &event);
const int ID_TEST_GAUGETIME = 100;
EVT_TIMER(ID_TEST_GAUGETIME,MyFrame::GaugeTimer)
//ProgressBar 생성
prgbar = new wxGauge(panel, ID_PROGRESSBAR, 500,wxPoint(40,10), wxSize(200,20),
wxGA_SMOOTH, wxDefaultValidator, wxT(""));
//Timer 생성
m_GaugeTimer = new wxTimer(this,ID_TEST_GAUGETIME);
이렇게 하니까 boxsizer에 올리지 않아도 되고, wxpoint 에 맞게 출력에 되더군요
Commented by
ExSuperstar
at 2010/02/09/ 08:22
임승욱// 방문해 주셔서 감사합니다. 그렇군요 ㅎㅎ. 예전에 작성한 코드에 대충 작성한거라서 그럴겁니다
저도 공부를 해보고 있는 중이라서.. 좋은 정보 주셔서 감사합니다
저도 공부를 해보고 있는 중이라서.. 좋은 정보 주셔서 감사합니다





