我正在寫一個C++程序與最上面的窗口,所以你沒有任何默認的方式調整大小,或者至少不是我的知識。所以我實現了一個調整大小,除了1個細節外,它工作正常。 當我調整右側或底部窗口的大小時,它完美地工作,但是當我調整左側或頂部的大小時,右側或底部的部分取決於調整大小的方式。我已經「部分地」固定了它,所以當你縮小尺寸時看起來很好,但是當你增大窗口的大小時,它仍然會抖動。c + + win32彈出窗口「搖動」調整大小
我也已經嘗試禁用和啓用重繪調整時,但螺絲東西完全地:對
這裏是我目前使用
GetCursorPos(&m_MousePos);
int x(m_rWindowStart.left),
y(m_rWindowStart.top),
w(m_pWindow->GetWidth()),
h(m_pWindow->GetHeight());
//sizing
switch (m_SizingDir)
{
case SIZING_DIR_LEFT:
//x += m_MousePos.x - m_MousePosOld.x;
w = m_rWindowStart.right - m_MousePos.x - m_MousePosOld.x + x;
w /= m_SnapSizing;
w *= m_SnapSizing;
x = m_rWindowStart.right - w;
break;
case SIZING_DIR_TOP:
y += m_MousePos.y - m_MousePosOld.y;
h = m_rWindowStart.bottom - y;
break;
case SIZING_DIR_RIGHT:
w = m_rWindowStart.right - m_rWindowStart.left + m_MousePos.x - m_MousePosOld.x;
break;
case SIZING_DIR_BOTTOM:
h = m_rWindowStart.bottom - m_rWindowStart.top + m_MousePos.y - m_MousePosOld.y;
break;
case SIZING_DIR_LEFTTOP:
x += m_MousePos.x - m_MousePosOld.x;
w = m_rWindowStart.right - x;
y += m_MousePos.y - m_MousePosOld.y;
h = m_rWindowStart.bottom - y;
break;
case SIZING_DIR_LEFTBOTTOM:
x += m_MousePos.x - m_MousePosOld.x;
w = m_rWindowStart.right - x;
h = m_rWindowStart.bottom - m_rWindowStart.top + m_MousePos.y - m_MousePosOld.y;
break;
case SIZING_DIR_RIGHTTOP:
w = m_rWindowStart.right - m_rWindowStart.left + m_MousePos.x - m_MousePosOld.x;
y += m_MousePos.y - m_MousePosOld.y;
h = m_rWindowStart.bottom - y;
break;
case SIZING_DIR_RIGHTBOTTOM:
w = m_rWindowStart.right - m_rWindowStart.left + m_MousePos.x - m_MousePosOld.x;
h = m_rWindowStart.bottom - m_rWindowStart.top + m_MousePos.y - m_MousePosOld.y;
break;
}
//window size snaps
w /= m_SnapSizing;
w *= m_SnapSizing;
h /= m_SnapSizing;
h *= m_SnapSizing;
//limit sizing
if (h < 20)
h = 20;
if (w < 20)
w = 20;
//move window (x, y, w, h, repaint)
m_pWindow->SetPosAndSize(x, y, w, h, true);
代碼,這是從調用的方法在m_pWindow
void Window::SetPosAndSize(int x, int y, int w, int h, bool repaint)
{
ASSERT(w >= 0, _T("w(Width) must be greater than 0"));
ASSERT(h >= 0, _T("h(Height) must be greater than 0"));
m_Width = w;
m_Height = h;
if(m_hWnd)
{
RECT rPos;
GetRect(rPos);
AdjustFromClient(w, h);
MoveWindow(m_hWnd, x, y, w, h, repaint);
}
}
void Window::GetRect(RECT& r) const
{
::GetWindowRect(m_hWnd, &r);
}
void Window::AdjustFromClient(int& w, int& h) const
{
RECT rSize2be = { 0, 0, w, h };
AdjustWindowRect(&rSize2be, m_Style, false);
w = rSize2be.right-rSize2be.left;
h = rSize2be.bottom-rSize2be.top;
}
,這裏是它看起來怎麼知道的人誰不完全理解這個問題的例子 http://www.megaupload.com/?d=4AXXPFKI
按ctrl並點擊移動窗口和 按alt,然後單擊附近的邊框來調整
因爲當您從底部/右側調整大小時緩衝區未重新繪製,當您調整頂部/左側的大小時,會重新繪製它。學習如何在GUI框架中進行雙緩衝。 –
我沒有看得太緊密,通常的問題是,當您移動窗口的左側或頂部時,鼠標的相對位置會發生變化。只是不要這樣做,而是寫WM_NCHITTEST的消息處理程序。 –
(請用你的新問題發佈一個新問題。堆棧溢出最適合一個問題,然後多個答案 - 這不是一個論壇) –