问题
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.
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?
回答1:
You could try with disabling NC area painting.
Something like below:
#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));
}
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.
UPDATED
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;
}
来源:https://stackoverflow.com/questions/4602936/delay-in-drawing-on-windows-7-os