gpt4 book ai didi

c++ - Win32 弹出窗口 "shaking"调整大小

转载 作者:行者123 更新时间:2023-11-30 04:32:03 24 4
gpt4 key购买 nike

我正在编写一个带有最顶层窗口的 C++ 程序,因此您没有任何默认的调整大小的方法,或者至少据我所知没有。所以我实现了调整大小,除了 1 个细节外,它工作正常。

当我在右侧或底部调整窗口大小时,它工作得很好,但是当我在左侧或顶部调整大小时,右侧或底部(取决于您调整大小的方式)会摇晃。我已经部分“修复”了它,因此当您缩小尺寸时它看起来不错,但是当您放大 window 时它仍然会晃动。

我也已经尝试过在调整大小时禁用和启用重绘,但这完全搞砸了,

这是我目前使用的代码

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

最佳答案

Hans 是对的......你正在努力解决这个问题。

WM_NCHITTEST 编写一个消息处理程序(在 MFC 中,覆盖 ::OnNcHitTest),返回 HT_BOTTOM、HT_LEFT 等,具体取决于您想要您的窗口,让 Windows 处理整个事情。

关于c++ - Win32 弹出窗口 "shaking"调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7932915/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com