调整主窗口大小时,静态控件轻微闪烁 [英] Static controls slightly flicker when main window is resized

查看:345
本文介绍了调整主窗口大小时,静态控件轻微闪烁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个复杂的绘画在我的主窗口的 WM_PAINT 处理程序中实现。

I have a complex painting to implement in my main window’s WM_PAINT handler.

我已提交了一张图片来说明:

I have submitted a picture bellow to illustrate it:

主窗口有静态控件,而不是按钮,风格 SS_NOTIFY

Main window has static controls, instead of buttons, which have style SS_NOTIFY.

当用户点击它们时,程序中会发生某些操作。

When user clicks on them, certain actions occur in program.

下面的图片显示了主窗口中的静态控件:

The following picture shows where static controls in the main window are:

橙色面板上的地图是一个 EMF ,左上角和右上角的徽标是 PNG 文件,其他图片是位图。

Map on the orange panel is an EMF file ,top left and right logos are PNG files, and other pictures are bitmaps.

,我决定在 WM_PAINT 中绘制整个图片,并将不可见的静态控件放在图片上与其对应的图片上。

In order to implement this task, I have decided to draw the entire picture in WM_PAINT, and to put invisible static controls over the images on the picture that correspond them.

因此,我只会返回 WM_CTLCOLORSTATIC 处理程序中的 NULL_BRUSH

Therefore, I only return NULL_BRUSH in WM_CTLCOLORSTATIC handler like this:

case WM_CTLCOLORSTATIC:
    return (LRESULT)( (HBRUSH)GetStockObject(NULL_BRUSH) );

我使用 Windows XP code> MS Visual Studio C ++ 2008 Express Edition 和纯Win32 API

I work on Windows XP, using MS Visual Studio C++ 2008 Express Edition and pure Win32 API.

一个音符:由于VS的快速版具有资源编辑器,资源文件和资源标题使用 ResEdit 从此处创建: http://www.resedit.net/

One note: since Express edition of VS doesn't have resource editor, resource file and resource header were created using ResEdit from here: http://www.resedit.net/.

当我调整窗口大小时,静态控件稍微闪烁。

When I resize my window, static controls slightly flicker.

我已经处理了 WM_ERASEBKGND code>(LRESULT)1 ),并且排除了样式 CS_VREDRAW CS_HREDRAW

I have handled WM_ERASEBKGND (returned (LRESULT)1), and I have excluded styles CS_VREDRAW and CS_HREDRAW from my window class-therefore flickering should not be caused because of this.

我的窗口没有 WS_CLIPCHILDREN style。

My window doesn’t have WS_CLIPCHILDREN style.

编辑:
为了回应下面的评论,我解释为什么我的窗口没有这种风格设置:

In response to the comment bellow, I explain why my window doesn't have this style set:

问题是,在静态控件所在的地方看到部分桌面图片。

The problem is that part of the desktop picture is seen where static controls are.

我已使用工具 GDIView ,从下载这里: http://www.nirsoft.net/utils/gdi_handles.html 跟踪

I have used the tool GDIView, downloaded from here: http://www.nirsoft.net/utils/gdi_handles.html to track down GDI leaks.

每次调整窗口大小时, GDIView 在区域列中显示+4,这意味着我泄漏区域。

Each time I resize my window, GDIView shows +4 in column for regions, which means that I leak regions.

我不知道这是怎么可能的,因为我不使用API

I can’t figure out how is this possible, since I do not use API’s that manipulate with regions.

为了说明我面对的是什么,我做了一个演示应用程序,并提出了彻底的评论:
http://www.filedropper.com/geotermistgrafika

To illustrate exactly what I am facing with, I have made a demo application , with thorough comments: http://www.filedropper.com/geotermistgrafika

我相信这是更有效的方法,然后张贴代码,因为它会消耗太多的空间。

I believe that this is more efficient way, then posting code since it will consume too much space.

我可以修改演示项目中的代码以摆脱闪烁吗?

How can I modify code in demo project to get rid of flickering?

我的方法错了,如果是,是什么是正确的?

Is my approach wrong, and if it is, what is the right one?

谢谢。
Regards。

Thank you. Regards.

推荐答案

当主窗口调整大小时, WM_SIZE 处理程序移动静态子窗口。

When the main window is resized the WM_SIZE handler moves the static child windows.

当子窗口移动时,Windows会自动将子控件的客户区从旧位置复制到新位置。

When a child window is moved, Windows automatically copies the client area of the child control from the old location to the new location.

然后主窗口将在 WM_PAINT 处理程序中重新绘制自己。

The main window will then repaint itself in the WM_PAINT handler.

换句话说,当窗口调整大小时,所有静态控件移动到其新位置,然后重新绘制窗口的其余部分。

In other words, when the window is resized all the static controls move to their new position and then the rest of the window is repainted. This lack of synchronization appears as flicker.

您可以通过将 SWP_NOCOPYBITS 标志传递给 SetWindowPos

You can avoid this by passing the SWP_NOCOPYBITS flag to SetWindowPos.

这篇关于调整主窗口大小时,静态控件轻微闪烁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆