棒法芬芳
  1. using System;
  2. using System.Drawing;
  3. using System.Runtime.InteropServices;
  4. using System.Windows.Forms;

  5. namespace repaint_form
  6. {
  7.     public partial class Form1 : Form
  8.     {
  9.         Image img = Image.FromFile(Application.StartupPath + "\\Command_Block.png");

  10.         [DllImport("dwmapi.dll")]
  11.         public static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, ref int attrValue, int attrSize);

  12.         [DllImport("dwmapi.dll")]
  13.         public static extern int DwmIsCompositionEnabled(ref int pfEnabled);
  14.         [DllImport("user32.dll")]
  15.         public static extern IntPtr GetWindowDC(IntPtr hm);
  16.         [DllImport("user32.dll")]
  17.         public static extern void ReleaseDC(IntPtr m, IntPtr h);

  18.         private bool m_aeroEnabled;                     // variables for box shadow
  19.         private const int CS_DROPSHADOW = 0x00020000;
  20.         private const int WM_NCPAINT = 0x0085;
  21.         private const int WM_NCACTIVATE = 0x86;
  22.         private const int WM_ACTIVATEAPP = 0x001C;

  23.         public Form1()
  24.         {
  25.             m_aeroEnabled = false;
  26.             //FormBorderStyle = FormBorderStyle.None;
  27.             InitializeComponent();
  28.         }

  29.         protected override void WndProc(ref Message m)
  30.         {
  31.             base.WndProc(ref m);
  32.             switch (m.Msg)
  33.             {
  34.                 case 0x84:
  35.                     //这里是鼠标的移动事件
  36.                     break;
  37.                 case 0x86: //WM_NCACTIVATE
  38.                     goto case 0x85;
  39.                 case 0x85: //WM_NCPAINT
  40.                     //CaptionButtonSize获取窗口标题栏中的按钮的标准大小(以像素为单位)。
  41.                     Size si = new Size(SystemInformation.CaptionButtonSize.Width, SystemInformation.CaptionButtonSize.Height);
  42.                     IntPtr hDC = GetWindowDC(m.HWnd);
  43.                     //把DC转换为.NET的Graphics就可以很方便地使用Framework提供的绘图功能了
  44.                     Graphics gs = Graphics.FromHdc(hDC);
  45.                     Image img = Image.FromFile(Application.StartupPath + "\\Command_Block.png");
  46.                     //显示背景图片
  47.                     gs.DrawImage(img, 0, 0);
  48.                     gs.Dispose();
  49.                     //释放GDI资源
  50.                     ReleaseDC(m.HWnd, hDC);
  51.                     break;
  52.                 case 0xA1://WM_NCLBUTTONDOWN
  53.                     break;
  54.             }

  55.         }
  56.     }
  57. }
复制代码
上面为重绘代码
下图为重绘效果



可以看到重绘无效,请问如何使用WndProc方法对当前所在类体的窗体标题进行重绘?

棒法芬芳
这些代码是网上找的...实在找不到能用的...

PercyDan
是要改窗口图标?

第一页 上一页 下一页 最后一页