DeferWindowPos移動的多個視窗的父視窗必須相同。如果不同結果將
是錯誤的。我下面的函數原來是用DeferWindowPos來實現對RealGrid視窗的孫子視窗(這些孫子的父親可能不同)平移,結果很意外,改為
直接使用SetWindowPos就好了。希望Microsoft在下一版本的文檔中說明這個要求。
void CRealGrid::MoveTheChids(const CArray<HWND, HWND>& windows, int cx, int cy)
{
//DeferWindowPos移動的多個視窗的父視窗必須相同。
//HDWP hdwp = BeginDeferWindowPos((int)windows.GetCount());
for (int i=0; i<windows.GetCount(); ++i)
{
RECT rect;
//不宜用::GetClientRect(windows[i], &rect);,因為子視窗可能有Client Edge等,導致其客戶區大小小於其視窗大小。
::GetWindowRect(windows[i], &rect);
HWND hParent = ::GetParent(windows[i]);
::MapWindowPoints(HWND_DESKTOP, hParent, (LPPOINT)&rect, 2);
OffsetRect(&rect, cx, cy);
//DeferWindowPos(hdwp, windows[i], NULL, rect.left, rect.top, 0, 0, SWP_NOSIZE|SWP_NOZORDER);
::SetWindowPos(windows[i], NULL, rect.left, rect.top, 0, 0, SWP_NOSIZE|SWP_NOZORDER);
//讓CRealGrid不繪製孫子控制項地區
if(rect.left < 0)
rect.left = 0;
if(rect.top < 0)
rect.top = 0;
if(!IsRectEmpty(&rect))
{
::MapWindowPoints(hParent, m_hWnd, (LPPOINT)&rect, 2);
ValidateRect(&rect);
}
}
//EndDeferWindowPos(hdwp);
}