c#怎么通过重写 WndProc函数来同时实现无标题栏的窗体移动和禁止双击窗体最大化
因为我已经实现了无标题栏窗体的移动,当双击窗体时,会使窗体最大化,我想禁止找个消息,怎么写呢protectedoverridevoidWndProc(refMessage...
因为我已经实现了无标题栏窗体的移动,当双击窗体时,会使窗体最大化,我想禁止找个消息,怎么写呢
protected override void WndProc(ref Message m)
{
const int WM_NCHITTEST = 0x84;
const int HTCLIENT = 0x01;
const int HTCAPTION = 0x02;
const int WM_SYSCOMMAND = 0x112;
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);
return;
}
break;
case WM_SYSCOMMAND://禁止最大化
if (m.WParam.ToInt32() ==SC_MAXMIZE)
{
/./代码
return;
}
break;
default:
base.WndProc(ref m);
break;
}
}
当去掉第二个case后,可以拖动窗体,但是双击窗体会最大化;加上第二个case想禁止最大化,但是加了后什么功能也不能实现,怎么回事 展开
protected override void WndProc(ref Message m)
{
const int WM_NCHITTEST = 0x84;
const int HTCLIENT = 0x01;
const int HTCAPTION = 0x02;
const int WM_SYSCOMMAND = 0x112;
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);
return;
}
break;
case WM_SYSCOMMAND://禁止最大化
if (m.WParam.ToInt32() ==SC_MAXMIZE)
{
/./代码
return;
}
break;
default:
base.WndProc(ref m);
break;
}
}
当去掉第二个case后,可以拖动窗体,但是双击窗体会最大化;加上第二个case想禁止最大化,但是加了后什么功能也不能实现,怎么回事 展开
展开全部
protected override void WndProc(ref Message m)
{
const int WM_NCHITTEST = 0x84;
const int HTCLIENT = 0x01;
const int HTCAPTION = 0x02;
const int WM_SYSCOMMAND = 0x112;
const int SC_MAXMIZE = 0xF030;
const int WM_NCLBUTTONDBLCLK = 0xA3;
switch (m.Msg)
{
case 0x4e:
case 0xd:
case 0xe:
case 0x14:
base.WndProc(ref m);
break;
case WM_NCHITTEST://鼠标点任意位置后可以拖动窗体
this.DefWndProc(ref m);
if (m.Result.ToInt32() == HTCLIENT)
{
m.Result = new IntPtr(HTCAPTION);
return;
}
break;
case WM_NCLBUTTONDBLCLK://禁止双击最大化
Console.WriteLine(this.WindowState);
return;
break;
default:
base.WndProc(ref m);
break;
}
}
{
const int WM_NCHITTEST = 0x84;
const int HTCLIENT = 0x01;
const int HTCAPTION = 0x02;
const int WM_SYSCOMMAND = 0x112;
const int SC_MAXMIZE = 0xF030;
const int WM_NCLBUTTONDBLCLK = 0xA3;
switch (m.Msg)
{
case 0x4e:
case 0xd:
case 0xe:
case 0x14:
base.WndProc(ref m);
break;
case WM_NCHITTEST://鼠标点任意位置后可以拖动窗体
this.DefWndProc(ref m);
if (m.Result.ToInt32() == HTCLIENT)
{
m.Result = new IntPtr(HTCAPTION);
return;
}
break;
case WM_NCLBUTTONDBLCLK://禁止双击最大化
Console.WriteLine(this.WindowState);
return;
break;
default:
base.WndProc(ref m);
break;
}
}
展开全部
用不到重写WndProc,你只需要为窗体添加MouseDown和MouseUp就可以了。
MouseDown捕获鼠标的位置,MouseUp停止捕获。
禁止最大化,你就重写OnMaximizedBoundsChanged
MouseDown捕获鼠标的位置,MouseUp停止捕获。
禁止最大化,你就重写OnMaximizedBoundsChanged
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
protected override void WndProc(ref Message m)
{
const int WM_NCHITTEST = 0x84;
const int HTCLIENT = 0x01;
const int HTCAPTION = 0x02;
const int WM_SYSCOMMAND = 0x112;
const int SC_MAXMIZE = 0xF030;
const int WM_NCLBUTTONDBLCLK = 0xA3;
switch (m.Msg)
{
case 0x4e:
case 0xd:
case 0xe:
case 0x14:
base.WndProc(ref m);
break;
case WM_NCHITTEST://鼠标点任意位置后可以拖动窗体
this.DefWndProc(ref m);
if (m.Result.ToInt32() == HTCLIENT)
{
m.Result = new IntPtr(HTCAPTION);
return;
}
break;
case WM_NCLBUTTONDBLCLK://禁止双击最大化
Console.WriteLine(this.WindowState);
return;
break;
default:
base.WndProc(ref m);
break;
}
}
{
const int WM_NCHITTEST = 0x84;
const int HTCLIENT = 0x01;
const int HTCAPTION = 0x02;
const int WM_SYSCOMMAND = 0x112;
const int SC_MAXMIZE = 0xF030;
const int WM_NCLBUTTONDBLCLK = 0xA3;
switch (m.Msg)
{
case 0x4e:
case 0xd:
case 0xe:
case 0x14:
base.WndProc(ref m);
break;
case WM_NCHITTEST://鼠标点任意位置后可以拖动窗体
this.DefWndProc(ref m);
if (m.Result.ToInt32() == HTCLIENT)
{
m.Result = new IntPtr(HTCAPTION);
return;
}
break;
case WM_NCLBUTTONDBLCLK://禁止双击最大化
Console.WriteLine(this.WindowState);
return;
break;
default:
base.WndProc(ref m);
break;
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
用写这么多么?
6句话代码:
[DllImport("user32.dll")]
public static extern bool ReleaseCapture();
[DllImport("user32.dll")]
public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
//在窗体的mousedown事件下加
ReleaseCapture();
SendMessage(this.Handle, 0x0112, 0xF010 + 0x0002, 0);
6句话代码:
[DllImport("user32.dll")]
public static extern bool ReleaseCapture();
[DllImport("user32.dll")]
public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
//在窗体的mousedown事件下加
ReleaseCapture();
SendMessage(this.Handle, 0x0112, 0xF010 + 0x0002, 0);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2009-06-12
展开全部
不知你是否是要求禁止最大化,是可在窗体属性MaximizeBox设置false
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询