在Windows 7 OS上绘图延迟 [英] Delay in drawing on windows 7 OS

查看:112
本文介绍了在Windows 7 OS上绘图延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在我的应用程序(CMDIChildWnd类的对象)中标识一些Wnd. 为此,我使用计时器以特定的颜色绘制WND的边框,以便给人以闪烁的感觉.这在WinXP机器上可以很好地工作,但在Win7机器上却很痛苦.绘制突出显示的边框存在很大的延迟.
但是,当切换到优化以获得最佳性能设置时,一切都将顺利进行.

I need to identify some wnds in my application (objects of CMDIChildWnd class). To do this i am using a timer to draw the border of the wnd with specific color alternatively so as to give the feel of blinking. This works perfectly fine on WinXP machines, but faires miserably on Win7 machines; there is significant delay in painting the highlighted border.
However when switched to optimize for best performance setting everything works just smooth.

我正在使用CCLinetDC::Rectangle()方法绘制边框. Win7中的此API是否存在一些已知问题?如何在Win7上也能使用它?

I am using CCLinetDC::Rectangle() method to draw the border. Is there some known issue with this API in Win7? How can I make it work on Win7 as well?

推荐答案

您可以尝试禁用NC区域绘制.

You could try with disabling NC area painting.

类似以下内容:

#include <dwmapi.h>
...

HRESULT hr = E_FAIL;
if (IsVistaOrAbove())
{
    DWMNCRENDERINGPOLICY ncrp = DWMNCRP_DISABLED;
    hr = ::DwmSetWindowAttribute(m_hWnd, DWMWA_NCRENDERING_POLICY, &ncrp, sizeof(ncrp));
    ASSERT(SUCCEEDED(hr));
}

但是它也禁用了窗口上的Aero.

But it also disables Aero on the window.

因此,在客户区域而不是在边界显示眨眼会更直接.

So it would be more straightforward to show blink in the client area not in the border.

已更新

为了与XP兼容,您应该使用DWM API,如下所示:

For XP compatibility, you should use DWM APIs like this:

typedef HRESULT (WINAPI *pfnDwmIsCompositionEnabled)(BOOL *pfEnabled);
static pfnDwmIsCompositionEnabled s_DwmIsCompositionEnabled;
typedef HRESULT (WINAPI *pfnDwmSetWindowAttribute)(HWND hwnd, DWORD dwAttribute, LPCVOID pvAttribute, DWORD cbAttribute);
static pfnDwmSetWindowAttribute s_DwmSetWindowAttribute;
typedef HRESULT (WINAPI *pfnDwmGetWindowAttribute)(HWND hwnd, DWORD dwAttribute, LPCVOID pvAttribute, DWORD cbAttribute);
static pfnDwmGetWindowAttribute s_DwmGetWindowAttribute;


HMODULE hSysDll = LoadLibrary(_T("dwmapi.dll"));
if(hSysDll) // Loaded dwmapi.dll success, must Vista or above
{
    s_DwmIsCompositionEnabled = (pfnDwmIsCompositionEnabled)GetProcAddress(hSysDll, "DwmIsCompositionEnabled");
    s_DwmSetWindowAttribute = (pfnDwmSetWindowAttribute)GetProcAddress(hSysDll, "DwmSetWindowAttribute");
    s_DwmGetWindowAttribute =  (pfnDwmGetWindowAttribute)GetProcAddress(hSysDll, "DwmGetWindowAttribute");
}
...  
...  
bool IsAeroEnabled()
{
    BOOL bAero = FALSE;
    if(s_DwmIsCompositionEnabled)
        s_DwmIsCompositionEnabled(&bAero);
    return bAero != FALSE;
}
...  
...  
HRESULT ProxyDwmSetWindowAttribute(HWND hwnd, DWORD dwAttribute, LPCVOID pvAttribute, DWORD cbAttribute)
{
    if (s_DwmSetWindowAttribute)
    {
        return s_DwmSetWindowAttribute(hwnd, dwAttribute, pvAttribute, cbAttribute);
    }
    return E_FAIL;
}

这篇关于在Windows 7 OS上绘图延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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