我创建了一个少边框的形式,我设法使用以下方式为其分配系统菜单:
protected override CreateParams CreateParams
{
get
{
CreateParams param = base.CreateParams;
param.Style |= (WS_SYSMENU);
return param;
}
}
但现在,当我运行它时,它不再显示我通过WMNCHITTEST设置的自定义大小调整区域,如下所示:
protected override void WndProc(ref Message m)
{
const int wmNcHitTest = 0x84;
const int htBottomLeft = 16;
const int htBottomRight = 17;
if (m.Msg == wmNcHitTest)
{
int x = (int)(m.LParam.ToInt64() & 0xFFFF);
int y = (int)((m.LParam.ToInt64() & 0xFFFF0000) >> 16);
Point pt = PointToClient(new Point(x, y));
Size clientSize = ClientSize;
if (pt.X >= clientSize.Width - 40 && pt.Y >= clientSize.Height - 40 && clientSize.Height >= 40)
{
m.Result = (IntPtr)(htBottomRight);
return;
}
}
base.WndProc(ref m);
}
那么,如何克服这个?是否可以使用无边界形式的系统菜单,它也尊重WMNCHITTEST?
答案 0 :(得分:0)
这个CreateParams
覆盖应该可以解决问题:
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.Style = WS_CLIPCHILDREN | WS_MINIMIZEBOX | WS_SYSMENU;
cp.ClassStyle = CS_DBLCLKS;
return cp;
}
}
const int WS_CLIPCHILDREN = 0x2000000;
const int WS_MINIMIZEBOX = 0x20000;
const int WS_MAXIMIZEBOX = 0x10000;
const int WS_SYSMENU = 0x80000;
const int CS_DBLCLKS = 0x8;