MFC add scrollbar to CWnd member

Tal picture Tal · Dec 25, 2011 · Viewed 12.1k times · Source


I have a member of CWnd class name mywindow
and i want to add to it a scroll-bar.
how i can do it?

i try already to do:

mywindow.EnableScrollBarCtrl(SB_BOTH,TRUE);

it display both Horizontal and Vertical scroll-bars,
but i cannot push the buttons or move the scroll-bars.
i try also after the first command:

mywindow.EnableScrollBar(SB_BOTH,ESB_ENABLE_BOTH);

and it change nothing.

can someone could show me a simple example how to add scroll-bar to this member?

thanks a lot,
Tal

Answer

dwo picture dwo · Dec 27, 2011

Enabling the scroll bars isn't enough. You have to react to the window messages WM_HSCROLLand WM_VSCROLL. Using the GetScrollInfo method you get the position (value) of the scroll bars and then you draw your window content according to this position.