visual studio - Adding scrollbar to an activeX control in MFC -
i'm trying create activex control using microsoft foundation class library.
i have created control. it's graph control. have placed buttons on control well.
i trying add scrollbar control using cscrollbar
class.
i create control using cscrollbar::create
method. can see control when use activex control in application.
i have added onhscroll
method control class. derives colecontrol
class .
when scroll use cscrollbar::getscrollpos
scroll position returns zero.
here code creating scrollbar in activex control.
code control in mainclass.h file:
private: cscrollbar m_hscrollbar; protected: afx_msg void onhscroll(uint nsbcode, uint npos, cscrollbar* pscrollbar); declare_message_map()
code control in mainclass.cpp in oncreate()
method creating scrollbar:
m_hscrollbar.create(sbs_horz | ws_child| ws_visible , crect(rcbottomstrip.left , rcbottomstrip.bottom , rcbottomstrip.right , rcbottomstrip.bottom + (theight*3)/125),this, 315); m_hscrollbar.setscrollrange(0, 2048); scrollinfo scrollinfo; scrollinfo.cbsize = sizeof(scrollinfo); scrollinfo.fmask = sif_range; scrollinfo.nmin = 0; scrollinfo.nmax = 1128; scrollinfo.npage = 100; scrollinfo.npos = 0; scrollinfo.ntrackpos = 0; m_hscrollbar.setscrollinfo(&scrollinfo); m_hscrollbar.showscrollbar(true); m_hscrollbar.enablewindow(); m_hscrollbar.enableautomation();
in onhscroll
method return scroll position , moving scrollbar:
int curpos = m_hscrollbar.getscrollpos(); m_hscrollbar.setscrollpos(curpos);
i replaced cscrollbar , used hwnd instead. code changed this:
//mainclass.h
hwnd m_wndhscrollbar;
//mainclass.cpp
m_wndhscrollbar = (createwindowex( 0, // no extended styles scrollbar, // scroll bar control class (ptstr) null, // no window text ws_child | ws_visible // window styles | sbs_horz, // horizontal scroll bar style left, // horizontal position bottom, // vertical position right, // width of scroll bar height, // height of scroll bar m_hwnd, // handle main window (hmenu) id_hscrollbar, // no menu getmodulehandle(null), // instance owning window (pvoid) null // pointer not needed ));
Comments
Post a Comment