返回> 网站首页 

[转载]C#重绘标题栏

yoours2014-04-23 12:53:42 阅读 1527

简介一边听听音乐,一边写写文章。

 C# Code 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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, 00);
                gs.Dispose();
                //释放GDI资源  
                ReleaseDC(m.HWnd, hDC);
                break;
            case 0xA1://WM_NCLBUTTONDOWN  
                break;
        }
    }
}
微信小程序扫码登陆

文章评论

1527人参与,0条评论