urn TRUE; // return TRUE unless you set the focus to a control
}
void CEx06_5Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CEx06_5Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CEx06_5Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CEx06_5Dlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: Add your message handler code here and/or call default
//滑块条
CSliderCtrl* slider = (CSliderCtrl*)pScrollBar;
if(slider == &m_ctrlSlider)
{
int position = slider->GetPos();
char s[10];
wsprintf(s, " %d%% ", position);
CClientDC clientDC(this);
clientDC.SetTextColor(RGB(0,255,0));
clientDC.TextOut(200, 90, s);
}
//滚动条
int step;
step=1;
CScrollBar* scrollbar = (CScrollBar*)pScrollBar;
m_ctrlScrollbar.GetScrollPos();
if(scrollbar == &m_ctrlScrollbar)
{
switch(nSBCode)
{
case SB_THUMBPOSITION:
{
scrollbar->SetScrollPos(nPos);
break;
}
case SB_LINEUP:
{
if((m_ns-step) > 0)
{
m_ns=m_ns-step;
}
else
{
m_ns=0;
}
scrollbar->SetScrollPos(m_ns);
break;
}
case SB_LINEDOWN:
{
if((m_ns+step) < 100)
{
m_ns=m_ns+step;
}
else
{
m_ns=100;
}
scrollbar->SetScrollPos(m_ns);
break;
}
}
int position = scrollbar->GetScrollPos();
char s[10];
wsprintf(s, " %d%% ", position);
CClientDC clientDC(this);
clientDC.SetTextColor(RGB(0,0,255));
clientDC.TextOut(200, 150, s);
}
CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
}
void CEx06_5Dlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
int position = m_ctrlProgress.OffsetPos(1);
char s[10];
wsprintf(s, " %d%% ", position);
CClientDC clientDC(this);
clientDC.SetTextColor(RGB(0,0,255));
clientDC.TextOut(200, 50, s);
CDialog::OnTimer(nIDEvent);
}
void CEx06_5Dlg::OnButtonBegin()
{
// TODO: Add your control notification handler code here
SetTimer(1, 100, NULL);
m_ctrlProgress.SetPos(0);
}
void CEx06_5Dlg::OnButtonGoon()
{
// TODO: Add your control notification handler code here
SetTimer(1, 100, NULL);
}
void CEx06_5Dlg::OnButtonStop()
{
// TODO: Add your control notification handler code here
KillTimer(1);
}
BOOL CEx06_5Dlg::DestroyWindow()
{
// TODO: Add your specialized code here and/or call the base class
KillTimer(1);
return CDialog::DestroyWindow();
}