the scroll bar is used when the size of the drawn image exceeds the size of the customer area, move the scroll bar to observe the entire image. The cscrollview class is provided in VC to draw the scroll bar. In Step 6 of the Project Creation, select csrollview as the base class. If you have already selected cview as the base class, make the following changes to your Program : (1) Change cxxxview. CPP and cxxxview. replace all the cviews in H with csrollview (XXX is the project name) (2) use classwizard to add the response function oninitialupdate () for cxxxview (), add Code :
csize sizetotal;
sizetotal. cx = sizetotal. cy = 0;
setscrollsizes (mm_text, sizetotal);
the purpose of this Code is to complete the initialization of the scroll bar. If no problem occurs during compilation but an error occurs, setscrollsizes (INT nmapmode, size sizetotal, const size & sizepage = sizedefault, const size & sizeline = sizedefault) the meaning of the four parameters is: nmapmode indicates the ing mode, sizetotal indicates the scroll bar range, and sizepage indicates the scroll bar moving distance when you click the blank area of the scroll bar, sizeline indicates the moving distance of the scroll bar at the clicked endpoint.
After the settings are complete, pass the parameters used for your drawing to setscrollsizes () in ondraw to determine the scroll bar range. Note the following: in the drawing process, use the CDC * PDC to call the drawing directly. Do not use the DC of cclientdc (this) for drawing, otherwise, the figure will remain unchanged when the scroll bar is moved (it took two days to find the solution to this problem, which is stupid !)
We recommend that you add the following code:
// This is very important
Void cprogramview: onpreparedc (CDC * PDC, cprintinfo * pinfo)
{
// Todo: add your specialized code here and/or call the base class
Cscrollview: onpreparedc (PDC, pinfo );
}
Void cprogramview: onvscroll (uint nsbcode, uint NPOs, cscrollbar * pscrollbar)
{
// Todo: add your message handler code here and/or call default
Cscrollview: onvscroll (nsbcode, NPOs, pscrollbar );
}
Void cprogramview: onhscroll (uint nsbcode, uint NPOs, cscrollbar * pscrollbar)
{
// Todo: add your message handler code here and/or call default
Cscrollview: onhscroll (nsbcode, NPOs, pscrollbar );
}