- using System;
- using System.Drawing;
- using System.Runtime.InteropServices;
- using System.Windows.Forms;
- namespace repaint_form
- {
- public partial class Form1 : Form
- {
- Image img = Image.FromFile(Application.StartupPath + "\\Command_Block.png");
- [DllImport("dwmapi.dll")]
- public static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, ref int attrValue, int attrSize);
- [DllImport("dwmapi.dll")]
- public static extern int DwmIsCompositionEnabled(ref int pfEnabled);
- [DllImport("user32.dll")]
- public static extern IntPtr GetWindowDC(IntPtr hm);
- [DllImport("user32.dll")]
- public static extern void ReleaseDC(IntPtr m, IntPtr h);
- private bool m_aeroEnabled; // variables for box shadow
- private const int CS_DROPSHADOW = 0x00020000;
- private const int WM_NCPAINT = 0x0085;
- private const int WM_NCACTIVATE = 0x86;
- private const int WM_ACTIVATEAPP = 0x001C;
- public Form1()
- {
- m_aeroEnabled = false;
- //FormBorderStyle = FormBorderStyle.None;
- InitializeComponent();
- }
- 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.StartupPath + "\\Command_Block.png");
- //显示背景图片
- gs.DrawImage(img, 0, 0);
- gs.Dispose();
- //释放GDI资源
- ReleaseDC(m.HWnd, hDC);
- break;
- case 0xA1://WM_NCLBUTTONDOWN
- break;
- }
- }
- }
- }
下图为重绘效果
可以看到重绘无效,请问如何使用WndProc方法对当前所在类体的窗体标题进行重绘?
这些代码是网上找的...实在找不到能用的...
是要改窗口图标?