Tal
Tal

Reputation: 1215

MFC add scrollbar to CWnd member


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

Upvotes: 2

Views: 13725

Answers (3)

Roel
Roel

Reputation: 19642

Look up some scroll bar tutorials such as http://www.codeproject.com/KB/dialog/scrolling_support.aspx . In essence, dwo's comment above is what you need to do - handle those messages and set the virtual client area size.

Upvotes: 1

dwo
dwo

Reputation: 3636

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.

Upvotes: 2

CapelliC
CapelliC

Reputation: 60034

There must be some 'overflow' before scroll bars became active.

Write some 'sufficiently long' data in your view and the scrollbars will become active (at least, that was my experience time ago).

Usually scroll bars get handled 'automatically' from MFC components like (for instance) text editor or form view. I.e. will became visible when needed also without explicit call EnableScrollBarCtrl ...

Upvotes: 0

Related Questions