2


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

Tal
  • 1,145
  • 2
  • 14
  • 32

3 Answers3

2

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.

dwo
  • 3,576
  • 2
  • 22
  • 39
  • how i catch this massages? how i add my functions say: ON_WM_HSCROLL() and ON_WM_VSCROLL() that will call when the massages are call. thx for your help – Tal Jan 01 '12 at 07:40
  • If you do not know how to catch window messages, you will have a hard time! Anyhow, I think here is a good starting point to read: http://msdn.microsoft.com/de-de/library/0x0cx6b1.aspx – dwo Jan 01 '12 at 13:44
1

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.

Roel
  • 19,338
  • 6
  • 61
  • 90
  • Thank you @Roel. It's difficult to find answers when maintaining legacy projects. The archived Microsoft KB article you linked to by Jeff Parsons was very helpful since it had step-by-step guidance and code for implementing a vertical scrollbar. For others stumbling here, there's a KB archive on GitHub: https://github.com/jeffpar/kbarchive – iCode Feb 22 '21 at 15:55
0

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 ...

CapelliC
  • 59,646
  • 5
  • 47
  • 90
  • when i load to this window an image that larger the window, the window is become large, and it not show the scroll-bar automatically. so i need to understand how to do it. – Tal Dec 26 '11 at 08:14