發現了DeferWindowPos的一個問題,MSDN沒有說明

來源:互聯網
上載者:User

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);
}

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.