win32、scrollwindowex():如何显示“关闭窗口”的向上区域向下滚动后消失了?
我的应用程序的主窗口开始有很多东西,所以我需要一个垂直滚动条来适应客户区域内的所有内容。我编写了一个滚动条控件,正在处理像 SB_LINEDOWN 这样的 WM_VSCROLL 消息,并且滚动条移动得很好。最后一部分是使主窗口的内容随着滚动条的拇指移动,这对我来说似乎是一项艰巨的任务。这是我最好的尝试:
int dy = -( CurrPos - si.nPos );
RECT rctMainWindowArea = { 0, 0, 1000, main_window.bottom };
ScrollWindowEx( hwndMainWindow, 0, dy,( CONST RECT * ) &rctMainWindowArea,( CONST RECT * ) NULL,( HRGN ) NULL,( LPRECT ) NULL, SW_SCROLLCHILDREN | SW_INVALIDATE | SW_ERASE );
UpdateWindow( hwndMainWindow );
只要我向下滚动,它就可以工作。当我再次向上滚动时,一切都变得一团糟。我已经在谷歌上搜索这个问题一段时间了,看来我必须重新绘制主窗口丢失的客户区域。但是我不知道该怎么做。我在网上只找到了文本在编辑控件内滚动的示例。我需要滚动整个主窗口,其中有几个不同的基本控件、一些 bmp 图形、一些其他图形元素,如 TextOut()、RoundRect() 等。
我需要一些代码示例如何解决我的问题或至少一些简单的解释(我是业余程序员)。多谢 !
My application's main window is starting to have lots of stuff so I need a vertical scrollbar to fit everything inside client area. I coded a scrollbar control, WM_VSCROLL messages like SB_LINEDOWN are being processed and scrollbar moves nicely. The last part is to make the content of a main window to move along with the thumb of a scrollbar and it seems a bit hard task for me. This is my best try:
int dy = -( CurrPos - si.nPos );
RECT rctMainWindowArea = { 0, 0, 1000, main_window.bottom };
ScrollWindowEx( hwndMainWindow, 0, dy,( CONST RECT * ) &rctMainWindowArea,( CONST RECT * ) NULL,( HRGN ) NULL,( LPRECT ) NULL, SW_SCROLLCHILDREN | SW_INVALIDATE | SW_ERASE );
UpdateWindow( hwndMainWindow );
It works as long I'm scrolling down. When I scroll back up again everything gets messed up. I've been googling about this issue for a while and it seems that I have to redraw the lost client area of main window. However I have no idea how to do it. I've found on the web only examples where text is being scrolled inside edit control. I need to scroll whole main window which has couple of different basic controls, some bmp graphic, some other graphic elements like TextOut(), RoundRect() and so on.
I need some code examples how to solve my issue or at least some simple explanation (I'm amateur programmer). Thanks a lot !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Windows 不会跟踪窗口滚动的量,因此当它要求您重新绘制窗口的一部分时,您需要根据滚动的量来更改绘制的内容。
最简单的方法是调整窗口原点以匹配您已完成的滚动量。您的
WM_PAINT
处理程序可能如下所示。offsetX
和offsetY
分别是您在 X 和 Y 方向上滚动的距离。Windows doesn't keep track of how much the window has scrolled, so when it asks you to repaint part of the window, you need to change what you paint based on how much scrolling you've done.
The easiest way to do this is to adjust the window origin to match the amount of scrolling you've done. Your
WM_PAINT
handler might look something like this.offsetX
andoffsetY
are the distances you've scrolled in the X and Y directions respectively.