我需要在我的应用程序中识别一些wnds(CMDIChildWnd类的对象)。 要做到这一点,我使用计时器来绘制具有特定颜色的wnd的边框,以便给人一种闪烁的感觉。这在WinXP机器上运行得非常好,但在Win7机器上很糟糕;绘制突出显示的边框会有明显的延迟 但是,当切换到优化以获得最佳性能设置时,一切都很顺利。
我使用CCLinetDC::Rectangle()
方法绘制边框。在Win7中,此API存在一些已知问题吗?我怎样才能使它在Win7上运行?
答案 0 :(得分:1)
您可以尝试禁用NC区域绘画。
如下所示:
#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。
因此,在不在边界的客户区显示闪烁会更直接。
<强>已更新强>
对于XP兼容性,您应该使用这样的DWM API:
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;
}