C# 中使无标题窗口用鼠标点任意位置实现移动,但是双击会最大化,谁知道怎么屏蔽

大哥大姐们帮我教一下,C# 中使无标题窗口用鼠标点任意位置实现移动,但是双击会最大化,谁知道怎么屏蔽?

protected override void WndProc(ref Message m)
{
const int WM_NCHITTEST = 0x84;
const int HTCLIENT = 0x01;
const int HTCAPTION = 0x02;
const int WM_SYSCOMMAND = 0x0112;
const int SC_MAXMIZE = 0xF030;
switch (m.Msg)
{
case WM_NCHITTEST:
this.DefWndProc(ref m);
if (m.Result.ToInt32() == HTCLIENT)
m.Result = new IntPtr(HTCAPTION);
break;
case WM_SYSCOMMAND:
if (m.WParam.ToInt32() == SC_MAXMIZE)
MessageBox.Show("");
break;
default:
base.WndProc(ref m);
break;
}
}
第一个case是实现用鼠标点任意位置移动窗体
为什么加了第二个case以后就不能任意位置移动窗体了呢,
麻烦行家指点下
最新回答
不交电费瞎发啥光

2024-11-03 01:28:36

protected override void WndProc(ref Message m)
{
if (m.Msg == 0x0201)
{
m.Msg = 0x00A1;//更改消息为非客户区按下鼠标
m.LParam = IntPtr.Zero;
m.WParam = new IntPtr(2);//鼠标放在标题栏内
}
base.WndProc(ref m);
}
感情终究破碎

2024-11-03 00:59:57

this.ClientSize = new System.Drawing.Size(987, 532);
this.MaximumSize = new System.Drawing.Size(995, 566);

这样最大化就没用了
薄荷糖味的吻

2024-11-03 05:02:49

protected override void WndProc(ref Message m)
{
const int WM_SYSCOMMAND = 0x0112;

const int SC_MAXIMIZE = 0xF030;

if (m.Msg == WM_SYSCOMMAND && ((int)m.WParam == SC_MAXIMIZE ))
{

base.WindowState = FormWindowState.Normal;

return;
}
base.WndProc(ref m);
}