MFC向CWnd成员添加滚动条
我有一个 CWnd 类的成员,名称为 mywindow
我想为其添加一个滚动条。
我该怎么做?
我已经尝试这样做:
mywindow.EnableScrollBarCtrl(SB_BOTH,TRUE);
它显示水平和垂直滚动条,
但我无法按下按钮或移动滚动条。
我也在第一个命令之后尝试:
mywindow.EnableScrollBar(SB_BOTH,ESB_ENABLE_BOTH);
它没有改变任何东西。
有人可以向我展示一个简单的示例如何向该成员添加滚动条吗?
多谢,
塔尔
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
启用滚动条还不够。您必须对窗口消息
WM_HSCROLL
和WM_VSCROLL
做出反应。使用GetScrollInfo
方法,您可以获取滚动条的位置(值),然后根据该位置绘制窗口内容。Enabling the scroll bars isn't enough. You have to react to the window messages
WM_HSCROLL
andWM_VSCROLL
. Using theGetScrollInfo
method you get the position (value) of the scroll bars and then you draw your window content according to this position.查找一些滚动条教程,例如 http://www.codeproject.com/KB/dialog /scrolling_support.aspx 。本质上,上面 dwo 的评论就是您需要做的 - 处理这些消息并设置虚拟客户区域大小。
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.
在滚动条激活之前必须有一些“溢出”。
在视图中写入一些“足够长”的数据,滚动条将变为活动状态(至少,这是我不久前的经验)。
通常,滚动条由 MFC 组件(例如文本编辑器或表单视图)“自动”处理。 Ie 将在需要时变得可见,也无需显式调用 EnableScrollBarCtrl ...
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 ...