mfc_progress_ctrl_1 - 8BitsCoding/RobotMentor GitHub Wiki
progress ctrl κΈ°λ³Έ μ¬μ©λ² + λλ§μ progress ctrlλ§λ€κΈ°
class TW_ProgressCtrl {
private:
int m_pos, m_min, m_max;
COLORREF m_bk_color, m_fore_color;
CRect m_rect;
public:
TW_ProgressCtrl() : m_rect(0, 0, 0, 0)
{
m_pos = 0;
m_min = 0;
m_max = 0;
m_bk_color = RGB(0, 80, 160);
m_fore_color = RGB(0, 160, 255);
}
CRect GetRect()
{
return m_rect;
}
void Update(CWnd * ap_parent) {
ap_parent->InvalidateRect(m_rect, 0);
}
void Update(CWnd * ap_parent, int a_pos) {
ap_parent->InvalidateRect(m_rect, 0);
SetPos(a_pos);
}
void Create(CWnd * ap_parent, int a_quide_ctrl_id) {
ap_parent->GetDlgItem(a_quide_ctrl_id)->GetWindowRect(m_rect);
ap_parent->ScreenToClient(m_rect);
}
void Create(CRect a_rect) {
m_rect = a_rect;
}
void SetRange(int a_min, int a_max) {
if (a_min == a_max) return;
if (a_max < m_min) {
m_max = a_min;
m_min = a_max;
}
m_max = a_max;
m_min = a_min;
}
inline void SetPos(int a_pos) {
m_pos = a_pos;
if (m_min > a_pos) m_pos = m_min;
else if (m_max < a_pos) m_pos = m_max;
}
int GetPos() {
return m_pos;
}
void SetColor(COLORREF a_bk_color, COLORREF a_fore_color)
{
m_bk_color = a_bk_color;
m_fore_color = a_fore_color;
}
void Draw(CDC * ap_dc) {
int pos = m_pos * m_rect.Width() / (m_max-m_min);
ap_dc->FillSolidRect(m_rect.left + pos, m_rect.top, m_rect.Width(), m_rect.Height(), m_bk_color);
ap_dc->FillSolidRect(m_rect.left, m_rect.top, pos, m_rect.Height(), m_fore_color);
}
};
// Dlg.h
CProgressCtrl m_my_progress;
CRect m_user_rect;
TW_ProgressCtrl m_user_progress;
BOOL CMFCApplication1Dlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
// μ΄ λν μμμ μμ΄μ½μ μ€μ ν©λλ€. μμ© νλ‘κ·Έλ¨μ μ£Ό μ°½μ΄ λν μμκ° μλ κ²½μ°μλ
// νλ μμν¬κ° μ΄ μμ
μ μλμΌλ‘ μνν©λλ€.
SetIcon(m_hIcon, TRUE); // ν° μμ΄μ½μ μ€μ ν©λλ€.
SetIcon(m_hIcon, FALSE); // μμ μμ΄μ½μ μ€μ ν©λλ€.
// TODO: μ¬κΈ°μ μΆκ° μ΄κΈ°ν μμ
μ μΆκ°ν©λλ€.@
//m_my_progress.SetRange(0, 200);
SetTimer(1, 50, NULL);
//GetDlgItem(IDC_USER_RECT)->GetWindowRect(m_user_rect);
//ScreenToClient(m_user_rect);
m_user_progress.Create(this, IDC_USER_RECT);
m_user_progress.SetRange(0, 200);
m_user_progress.SetColor(RGB(160, 50, 0), RGB(255, 220, 0));
return TRUE; // ν¬μ»€μ€λ₯Ό 컨νΈλ‘€μ μ€μ νμ§ μμΌλ©΄ TRUEλ₯Ό λ°νν©λλ€.
}
void CMFCApplication1Dlg::OnPaint()
{
CPaintDC dc(this); // 그리기λ₯Ό μν λλ°μ΄μ€ 컨ν
μ€νΈμ
λλ€.
if (IsIconic())
{
// ...
}
else
{
int pos = m_my_progress.GetPos()*2;
dc.FillSolidRect(pos, 0, 100*2, 30, RGB(0,80,160));
dc.FillSolidRect(0, 0, pos, 30, RGB(0, 80, 255));
//pos = m_my_progress.GetPos() * m_user_rect.Width()/100;
//dc.FillSolidRect(m_user_rect.left+pos, m_user_rect.top, m_user_rect.Width(), m_user_rect.Height(), RGB(0, 80, 160));
//dc.FillSolidRect(m_user_rect.left, m_user_rect.top, pos, m_user_rect.Height(), RGB(0, 80, 255));
m_user_progress.Draw(&dc);
// CDialogEx::OnPaint();
}
}
void CMFCApplication1Dlg::OnTimer(UINT_PTR nIDEvent)
{
if (nIDEvent == 1) {
int pos = m_my_progress.GetPos();
pos = (pos + 1) % 101;
m_my_progress.SetPos(pos);
InvalidateRect(CRect(0,0,100*2,30),0);
//InvalidateRect(m_user_rect, 0);
//m_user_progress.SetPos(pos);
//m_user_progress.Update(this);
m_user_progress.Update(this, pos);
}
else {
CDialogEx::OnTimer(nIDEvent);
}
}
void CMFCApplication1Dlg::OnDestroy()
{
CDialogEx::OnDestroy();
KillTimer(1);
}