Graphics Reference
In-Depth Information
. // removed content similar to that from Listing 2.6 (Tutorial 2.2) .
void CTutorialDlg::DoDataExchange(CDataExchange * pDX) {
A2: DDX _ Text(pDX, IDC _ H _ SLIDER _ ECHO, m _ HSliderEcho);
DDX _ Text(pDX, IDC _ V _ SLIDER _ ECHO, m _ VSliderEcho);
B2: DDX _ Control(pDX, IDC _ V _ SLIDER _ BAR, m _ VSliderBar);
DDX _ Control(pDX, IDC _ H _ SLIDER _ BAR, m _ HSliderBar);
.
BEGIN _ MESSAGE _ MAP(CTutorialDlg, CDialog)
C2: ON _ WM _ HSCROLL()
ON _ WM _ VSCROLL()
.
BOOL CTutorialDlg:: OnInitDialog () {
A3: m _ VSliderEcho.Format(" % d", 0); m _ HSliderEcho.Format(" % d", 0);
B3: m _ VSliderBar.SetRange(0, 100, TRUE); m _ VSliderBar.SetPos(0);
.
B4: UpdateData( false );
.
C3: This is the Horizontal scroll bar serviceroutine we override from MFC.
void CTutorialDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar * pScrollBar) {
// check to make sure we know which slider bar is generating the events
if (pScrollBar == (CScrollBar * )&m _ HSliderBar) {
C4: int value = m _ HSliderBar.GetPos();
C5: m _ HSliderEcho.Format(" % d", value);
C6: UpdateData( false );
.
C7: This is the Vertical scroll bar serviceroutine we override from MFC.
void CTutorialDlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar * pScrollBar) {
// content complements that of OnHScroll
Listing 2.7. (cont.)
HandV. To avoid repeating
every sentence with an “ H
for horizontal and an “ V ”for
vertical, we omit the “ H/V
characters and use one iden-
tifier to refer to both. For
example, OnScroll() is re-
ferring to On H Scroll() and
On V Scroll .
Slider bar service routines (C). At label C1, we declare OnScroll() for
servicing all horizontal and vertical scroll bars. Notice that before the ser-
vice registration at label C2, these two are just simple functions. At label
C2, we register for the ON _ WM _ SCROLL (on window scroll) event. Notice
that no callback functions are passed in. The horizontal and vertical scroll
Search WWH ::




Custom Search