using System.Runtime.InteropServices;
public partial class frmMain : Form
{
[DllImport("User32.dll")]
private static extern IntPtr GetWindowDC(IntPtr hwnd);
[DllImport("User32.dll")]
private static extern int ReleaseDC(IntPtr hwnd, IntPtr hdc);
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
switch (m.Msg)
{
case 0x84:
//这里是鼠标的移动事件
break;
case 0x86: //WM_NCACTIVATE
goto case 0x85;
case 0x85: //WM_NCPAINT
//CaptionButtonSize获取窗口标题栏中的按钮的标准大小(以像素为单位)。
Size si = new Size(SystemInformation.CaptionButtonSize.Width, SystemInformation.CaptionButtonSize.Height);
IntPtr hDC = GetWindowDC(m.HWnd);
//把DC转换为.NET的Graphics就可以很方便地使用Framework提供的绘图功能了
Graphics gs = Graphics.FromHdc(hDC);
Image img = Image.FromFile(Application.ExecutablePath.Replace(".EXE", ".png"));
//显示背景图片
gs.DrawImage(img, 0, 0);
gs.Dispose();
//释放GDI资源
ReleaseDC(m.HWnd, hDC);
break;
case 0xA1://WM_NCLBUTTONDOWN
break;
}
}
}
C#重绘标题栏
最新推荐文章于 2024-04-25 17:53:40 发布