我想自绘窗体标题栏,但是皮肤的标题栏高度和系统的不一样,所以要将标题栏的高度加大,我于是响应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)); //40为标题栏高度
Marshal.StructureToPtr(Params, m.LParam, false);
}
base.WndProc(ref m);
}
}
}
但发现如果不断最大化,还原的话窗体会越来越小,怎么回事?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)); //40为标题栏高度
Marshal.StructureToPtr(Params, m.LParam, false);
}
base.WndProc(ref m);
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货