1. Use of the ScrollBar control bar
First, suppose you add a horizontal scroll bar and associate a control variable m_hscroll to the scroll bar control;
Set the scroll bar range M_hscroll in the initialization dialog function. SetScrollRange (0,100);
Maximum minimum setting, and setting the position of the scroll bar slider at the beginning of the M_hscroll. SetScrollPos (5);
Then, the message Response command wm_hscroll that adds a scroll bar automatically adds void Ccolordlg::onhscroll (UINT nsbcode, UINT NPOs, cscrollbar* pscrollbar).
The program inside the function is shown below
void Ccolordlg::onhscroll (UINT nsbcode, UINT NPOs, cscrollbar* Pscrollbar)
{
TODO: Add the message Handler code here and/or call the default value
int Pos=m_hscroll. GetScrollPos ();
movealways=pos*unitmove;//has moved the distance
CDC *pdc=getdlgitem (idc_picture)->getdc ();//The sentence is another function statement, not the scroll bar
Switch (Nsbcode)
{
Case Sb_lineup:
Pos-=1;
if (pos<0)
{
pos=0;
}
Pdc->bitblt (0,0,rect. Width (), Rect. Height (), &dcmem,movealways-unitmove,0,srccopy);
M_hscroll. SetScrollPos (Pos);
Break
Case Sb_linedown:
Pos+=1;
if (pos>100)
{
pos=100;
}
Pdc->bitblt (0,0,rect. Width (), Rect. Height (), &dcmem,movealways+unitmove,0,srccopy);
M_hscroll. SetScrollPos (Pos);
Break
Case Sb_pageup:
pos-=10;
if (pos<0)
{
pos=0;
}
Pdc->bitblt (0,0,rect. Width (), Rect. Height (), &dcmem,movealways-(unitmove*10), 0,srccopy);
M_hscroll. SetScrollPos (Pos);
Break
Case Sb_pagedown:
pos+=10;
if (pos>100)
{
pos=100;
}
Pdc->bitblt (0,0,rect. Width (), Rect. Height (), &dcmem,movealways+ (unitmove*10), 0,srccopy);
M_hscroll. SetScrollPos (Pos);
Break
Case Sb_top:
pos=0;
M_hscroll. SetScrollPos (Pos);
Break
Case Sb_bottom:
pos=100;
Pdc->bitblt (0,0,rect. Width (), Rect. Height (), &dcmem,xlast-rect. Width (), 0,srccopy);
M_hscroll. SetScrollPos (Pos);
Break
Case Sb_thumbposition:
Pos=npos;
Pdc->bitblt (0,0,rect. Width (), Rect. Height (), &dcmem,unitmove*npos,0,srccopy);
M_hscroll. SetScrollPos (Pos);
Break
Case Sb_thumbtrack://Drag scroll box to specified position. NPOs is the
Pos=npos;
Pdc->bitblt (0,0,rect. Width (), Rect. Height (), &dcmem,unitmove*pos,0,srccopy);
M_hscroll. SetScrollPos (Pos);
Break
}
Cdialog::onhscroll (Nsbcode, NPOs, Pscrollbar); When you use the scrollbar you added, annotate the sentence, or you can't set the value of the POS, it always makes the pos=0
}
2. dialog box standard scroll bar use
First, the initial setting of the OnInitDialog function
BOOL Ccolordlg::oninitdialog ()
{
CDialog::OnInitDialog ();
TODO: Add additional initialization here
Scrollinfo Vinfo;
Vinfo.cbsize=sizeof (Vinfo);
Vinfo.fmask=sif_all;
vinfo.npage=10;
vinfo.nmax=100;
vinfo.nmin=0;
Setscrollinfo (Sb_horz,&vinfo);
return TRUE; Return TRUE unless your set the focus to a control
Exception: OCX property page should return FALSE
}
Similarly, adding a message response Command Wm_hscroll automatically adds void Ccolordlg::onhscroll (UINT nsbcode, UINT NPOs, cscrollbar* pscrollbar).
Void Ccolordlg::onhscroll (UINT nsbcode, UINT NPOs, cscrollbar* pscrollbar)
{
//TODO: Add Message Handler code here and/or call default value
Scrollinfo Scrollinfo;
Getscrollinfo (Sb_horz,&scrollinfo,sif_all);
movealways=scrollinfo.npos*unitmove;//has moved distance
CDC *pdc=getdlgitem (idc_picture)->getdc ();
switch (nsbcode)
{
Case sb_lineup:
Scrollinfo.npos-=1;
if (scrollinfo.npos<scrollinfo.nmin)
{
Scrollinfo.npos=scrollinfo.nmin;
}
Pdc->bitblt (0,0,rect. Width (), Rect. Height (), &dcmem,movealways-unitmove,0,srccopy);
Setscrollinfo (Sb_horz,&scrollinfo,sif_all);
Break
Case Sb_linedown:
Scrollinfo.npos+=1;
if (Scrollinfo.npos>scrollinfo.nmax)
{
Scrollinfo.npos=scrollinfo.nmax;
}
Pdc->bitblt (0,0,rect. Width (), Rect. Height (), &dcmem,movealways+unitmove,0,srccopy);
Setscrollinfo (Sb_horz,&scrollinfo,sif_all);
Break
Case Sb_pageup:
scrollinfo.npos-=10;
if (scrollinfo.npos<scrollinfo.nmin)
{
Scrollinfo.npos=scrollinfo.nmin;
}
Pdc->bitblt (0,0,rect. Width (), Rect. Height (), &dcmem,movealways-(unitmove*10), 0,srccopy);
Setscrollinfo (Sb_horz,&scrollinfo,sif_all);
Break
Case Sb_pagedown:
scrollinfo.npos+=10;
if (Scrollinfo.npos>scrollinfo.nmax)
{
Scrollinfo.npos=scrollinfo.nmax;
}
Pdc->bitblt (0,0,rect. Width (), Rect. Height (), &dcmem,movealways+ (unitmove*10), 0,srccopy);
Setscrollinfo (Sb_horz,&scrollinfo,sif_all);
Break
Case Sb_top:
Scrollinfo.npos=scrollinfo.nmin;
Setscrollinfo (Sb_horz,&scrollinfo,sif_all);
Break
Case Sb_bottom:
Scrollinfo.npos=scrollinfo.nmax;
Pdc->bitblt (0,0,rect. Width (), Rect. Height (), &dcmem,xlast-rect. Width (), 0,srccopy);
Setscrollinfo (Sb_horz,&scrollinfo,sif_all);
Break
Case Sb_thumbposition:
Scrollinfo.npos=npos;
Pdc->bitblt (0,0,rect. Width (), Rect. Height (), &dcmem,unitmove*npos,0,srccopy);
Setscrollinfo (Sb_horz,&scrollinfo,sif_all);
Break
Case Sb_thumbtrack://Drag scroll box to specified position. NPOs is the
Scrollinfo.npos = NPOs;
Pdc->bitblt (0,0,rect. Width (), Rect. Height (), &dcmem,unitmove*pos,0,srccopy);
Setscrollinfo (Sb_horz,&scrollinfo,sif_all);
Break
}
Cdialog::onhscroll (Nsbcode, NPOs, Pscrollbar);
}