Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Visual C++ and MFC Fundamentals Chapter 18: Progress-Based Controls


CurPos--;
break;

case SB_LINEDOWN:
if (CurPos < 255)
CurPos++;
break;

case SB_BOTTOM:
CurPos = 255;
break;

case SB_ENDSCROLL:
break;

case SB_THUMBPOSITION:
CurPos = nPos;
break;

case SB_THUMBTRACK:
CurPos = nPos;
break;
}

// Set the new position of the thumb (scroll box).
pScrollBar->SetScrollPos(CurPos);

// Update each color based on the positions of the scroll bar controls
ColorRed = 255 - m_ScrollRed.GetScrollPos();
ColorGreen = 255 - m_ScrollGreen.GetScrollPos();
ColorBlue = 255 - m_ScrollBlue.GetScrollPos();

CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
}


  1. Create a timer in the OnInitDialog() event as follows:


SetTimer(1, 40, NULL);

return TRUE; // return TRUE unless you set the focus to a control
}


  1. Generate a WM_TIMER message for the dialog box and implement it as follows:


void CPreviewerDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
PaintPreviewArea();

CDialog::OnTimer(nIDEvent);
}


  1. Test the application

Free download pdf