我想自己画的标题栏,但我的标题栏的高度是不系统的,增加的标题栏的高度,然后,我响应WM_NCCALCSIZE
但如果我不断地最大化和恢复,形式会越来越小
出了什么事?
希望有人能回答,谢谢!
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
[DllImport("user32")]
public static extern int GetSystemMetrics(int nIndex);
private const int SM_CYCAPTION = 4;
private const int SM_CXFRAME = 32;
private const int SM_CYFRAME = 33;
private const int WM_NCCALCSIZE = 0x83;
[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
public int Left;
public int Top;
public int Right;
public int Bottom;
}
[StructLayout(LayoutKind.Sequential)]
public struct PWINDOWPOS
{
public IntPtr hwnd;
public IntPtr hwndInsertAfter;
public int x;
public int y;
public int cx;
public int cy;
public uint flags;
}
[StructLayout(LayoutKind.Sequential)]
public struct NCCALCSIZE_PARAMS
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
public RECT[] rgrc;
public PWINDOWPOS lppos;
}
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_NCCALCSIZE && m.WParam != IntPtr.Zero)
{
NCCALCSIZE_PARAMS Params;
Params = (NCCALCSIZE_PARAMS)m.GetLParam(typeof(NCCALCSIZE_PARAMS));
Params.rgrc[0].Top += 40 - (GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYFRAME)); //caption height
Marshal.StructureToPtr(Params, m.LParam, false);
}
base.WndProc(ref m);
}
}
}