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; } } }
作者:qq283868910 发表于2012-1-9 14:01:29 原文链接
阅读:43 评论:0 查看评论