c++ - CScrollbar SetScrollInfo has no effect -
i have similar problem one: how use mfc cscrollbar controls? figured out on_wm_vscroll
message sending parameter npos
equal 0. thought should set scrollbar setscrollinfo
method or @ least setscrollrange
, , try in precreatewindow()
of view class function (which derived cformview
).
nevertheless scrollbar doesn't seem data scrollinfo
structure.
here code samples:
bool cinterfaceview::precreatewindow(createstruct& cs) { // todo: modify window class or styles here modifying // createstruct cs drawphoto=false; //other unrelated variables; zoomfactor=1.0; info1.cbsize=sizeof(scrollinfo); //scrollinfo global variable info1.fmask=sif_all; info1.nmin=0; info1.nmax=100; info1.npage=2; info1.npos=5; info1.ntrackpos=2; scrollbar1.setscrollinfo(&info1); //the vertical scrollbar // scrollbar1.setscrollrange(0,100); //this has no effect either return cformview::precreatewindow(cs); }
vscroll message handler:
void cinterfaceview::onvscroll(uint nsbcode, uint npos, cscrollbar* pscrollbar) { int curpos = pscrollbar->getscrollpos(); //debug code: cstring test; int rn,rx; pscrollbar->getscrollrange(&rn,&rx); test.format(_t("%d %d %d\n"),npos,curpos,rx-rn); if(pscrollbar!=null) trace(test+_t(" dzialamy\n")); //end debug code //this part found on internet // determine new position of scroll box. switch (nsbcode) { case sb_left: // scroll far left. curpos = 0; break; case sb_right: // scroll far right. curpos = 100; break; case sb_endscroll: // end scroll. break; case sb_lineleft: // scroll left. if (curpos > 0) curpos--; break; case sb_lineright: // scroll right. if (curpos < 100) curpos++; break; case sb_pageleft: // scroll 1 page left. { // page size. scrollinfo info; scrollbar1.getscrollinfo(&info, sif_all); if (curpos > 0) curpos = max(0, curpos - (int) info.npage); } break; case sb_pageright: // scroll 1 page right { // page size. scrollinfo info; scrollbar1.getscrollinfo(&info, sif_all); if (curpos < 100) curpos = min(100, curpos + (int) info.npage); } break; case sb_thumbposition: // scroll absolute position. npos position curpos = npos; // of scroll box @ end of drag operation. break; case sb_thumbtrack: // drag scroll box specified position. npos curpos = npos; // position scroll box has been dragged to. break; } // set new position of thumb (scroll box). scrollbar1.setscrollpos(50); //orignally curpos cformview::onvscroll(nsbcode, 50, pscrollbar); // scrollbar1.setscrollpos(npos); }
so suspect, try set scrollbar either in wrong place, or wrong it? appreciate help.
precreatewindow called before window (and scroll bar) have been created. in view class should initialization in oninitialupdate. called after window creation before window becomes visible.
Comments
Post a Comment