gpt4 book ai didi

c# - 自定义 WndProc 不会停止调整大小

转载 作者:太空宇宙 更新时间:2023-11-03 14:39:43 25 4
gpt4 key购买 nike

我制作了一个处理 WM_CREATE、WM_ACTIVATE、WM_NCCALCSIZE 和 WM_NCHITTEST 的表单。它还覆盖了 paint 方法。

问题是当我调整表单大小时它不会停止调整大小。我试图将消息与工作窗口进行比较,但 spy++ 一直崩溃。这是我的 WndProc 代码:

protected override void WndProc(ref Message m)
{
IntPtr result = IntPtr.Zero;

bool callDWP = !Win32Interop.DwmDefWindowProc(m.HWnd, m.Msg, m.WParam, m.LParam, out result);

switch (m.Msg)
{
case Win32Messages.WM_CREATE:
{
int style = Win32Interop.GetWindowLong(m.HWnd, Win32Constants.GWL_STYLE);
int styleEx = Win32Interop.GetWindowLong(m.HWnd, Win32Constants.GWL_EXSTYLE);
Win32Interop.AdjustWindowRectEx(out RECT rc, style, false, styleEx);

}
break;

case Win32Messages.WM_ACTIVATE:
{
MARGINS margins = new MARGINS
{
cxLeftWidth = Math.Abs(BorderLeft),
cxRightWidth = Math.Abs(BorderRight),
cyBottomHeight = Math.Abs(BorderBottom),
cyTopHeight = Math.Abs(BorderTop)
};

int hr = Win32Interop.DwmExtendFrameIntoClientArea(m.HWnd, ref margins);

result = IntPtr.Zero;
}
break;

case Win32Messages.WM_NCCALCSIZE:
{
if (m.WParam != IntPtr.Zero)
{
result = IntPtr.Zero;
callDWP = false;
}
}
break;

case Win32Messages.WM_NCHITTEST:
{
{
int ht = DoHitTest(m);
Console.WriteLine(ht);
if (callDWP)
{
callDWP = (ht == Win32Constants.HTNOWHERE);
result = new IntPtr(ht);
}

}

break;
}
default:
{
base.WndProc(ref m);
break;
}
}
m.Result = result;
if (callDWP)
{
base.WndProc(ref m);
}
}

最佳答案

不要默认调用 base.WndProc(ref m);

关于c# - 自定义 WndProc 不会停止调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57746969/

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