win32、scrollwindowex():如何显示“关闭窗口”的向上区域向下滚动后消失了?

发布于 2025-01-08 10:14:13 字数 788 浏览 0 评论 0原文

我的应用程序的主窗口开始有很多东西,所以我需要一个垂直滚动条来适应客户区域内的所有内容。我编写了一个滚动条控件,正在处理像 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

茶底世界 2025-01-15 10:14:13

Windows 不会跟踪窗口滚动的量,因此当它要求您重新绘制窗口的一部分时,您需要根据滚动的量来更改绘制的内容。

最简单的方法是调整窗口原点以匹配您已完成的滚动量。您的 WM_PAINT 处理程序可能如下所示。 offsetXoffsetY 分别是您在 X 和 Y 方向上滚动的距离。

// Adjust coordinates to automatically scroll
POINT origin;
GetWindowOrgEx(hdc, &origin);
SetWindowOrgEx(hdc, origin.x + offsetX, origin.y + offsetY, 0);

// Move the paint rectangle into the new coordinate system
OffsetRect(&ps.rcPaint, offsetX, offsetY);

// Do the painting
// Change this to call your painting function
CWindow::DoPaint(hdc, ps);

// Restore coordinates
SetWindowOrgEx(hdc, origin.x, origin.y, 0);

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 and offsetY are the distances you've scrolled in the X and Y directions respectively.

// Adjust coordinates to automatically scroll
POINT origin;
GetWindowOrgEx(hdc, &origin);
SetWindowOrgEx(hdc, origin.x + offsetX, origin.y + offsetY, 0);

// Move the paint rectangle into the new coordinate system
OffsetRect(&ps.rcPaint, offsetX, offsetY);

// Do the painting
// Change this to call your painting function
CWindow::DoPaint(hdc, ps);

// Restore coordinates
SetWindowOrgEx(hdc, origin.x, origin.y, 0);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文