[原]C#タイトルバーを再描画

1733 ワード

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;
            }
        }
  }

作者:qq 283868910发表于2012-1-9 14:01:29
テキストリンク
読書:43コメント:0
コメントの表示