Click here to Skip to main content
15,915,093 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to draw an image on caption by handling WM_NCPAINT message. But the image gets overwritten soon after. What are the other messages that I need to handle if I need to ensure that image persists on the title bar? Or is this option no longer feasible on windows 10? I need the form to have the same theme as rest of the windows. So removing the standard frame is not an option for me.

C#
protected override void WndProc(ref Message m)
{
  if (m.Msg == Win32Utilities.WM_NCPAINT || m.Msg == Win32Utilities.WM_NCACTIVATE)
  {
    base.WndProc(ref m);
    IntPtr hdc = GetWindowDC(m.HWnd);
    try
    {
      using (Graphics g = Graphics.FromHdc(hdc))
      {

        Rectangle rect = GetMuxModeStatusRectangle();
        //Rectangle title = GetTitleBarRectangle();
        //g.Clip = new Region(title);
        //g.Clear(SystemColors.Window);
        g.DrawImageUnscaled(buttonBuffer, new Point(rect.X, rect.Y));

        g.Flush();
        }
      }
      finally
      {
        ReleaseDC(m.HWnd, hdc);
      }
  }
  else
  {
     base.WndProc(ref m);
  }
}


What I have tried:

I verified that image is getting drawn by commenting
base.WndProc(ref m);
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900