M
Martin
I'm trying to paint my own caption bar/title bar and also my own frame
border, but I'm having problems with modifying the clip region so
windows doesn't paint over my stuff when I call base.WndProc
I tried skipping base.WndProc alltogether, but it seems like the Menu
and Toolbar is part of the non client region and painted during
WM_NCPAINT and thus won't show up if base.WndProc is left out.
How do I modify the current clip region so windows won't repaint the
stuff I've already taken care of?
Below is the code taken from my Form
(NativeMethods contains all the [DllImport] stuff)
protected override void WndProc(ref Message m)
{
switch(m.Msg)
{
case NativeMethods.WM_NCPAINT: //0x0085
OnNCPaint(ref m, true);
break;
case NativeMethods.WM_NCACTIVATE://0x0086
OnNCPaint(ref m, (m.WParam.ToInt32() == 0? false : true) ) ;
break;
default:
break;
}
base.WndProc(ref m);
}
protected void OnNCPaint(ref Message m, bool active)
{
IntPtr hDC = NativeMethods.GetWindowDC(m.HWnd);
if (hDC.ToInt32() == 0)
{
return;
}
using(Graphics g = Graphics.FromHdc(hDC))
{
DrawBorder(g, active);
DrawCaption(g, active);
DrawIcon(g, active);
// TODO modify the clip region so windows won't try and paint
// over the stuff we just painted
}
m.Result = IntPtr.Zero;
NativeMethods.ReleaseDC(m.HWnd,hDC);
}
border, but I'm having problems with modifying the clip region so
windows doesn't paint over my stuff when I call base.WndProc
I tried skipping base.WndProc alltogether, but it seems like the Menu
and Toolbar is part of the non client region and painted during
WM_NCPAINT and thus won't show up if base.WndProc is left out.
How do I modify the current clip region so windows won't repaint the
stuff I've already taken care of?
Below is the code taken from my Form
(NativeMethods contains all the [DllImport] stuff)
protected override void WndProc(ref Message m)
{
switch(m.Msg)
{
case NativeMethods.WM_NCPAINT: //0x0085
OnNCPaint(ref m, true);
break;
case NativeMethods.WM_NCACTIVATE://0x0086
OnNCPaint(ref m, (m.WParam.ToInt32() == 0? false : true) ) ;
break;
default:
break;
}
base.WndProc(ref m);
}
protected void OnNCPaint(ref Message m, bool active)
{
IntPtr hDC = NativeMethods.GetWindowDC(m.HWnd);
if (hDC.ToInt32() == 0)
{
return;
}
using(Graphics g = Graphics.FromHdc(hDC))
{
DrawBorder(g, active);
DrawCaption(g, active);
DrawIcon(g, active);
// TODO modify the clip region so windows won't try and paint
// over the stuff we just painted
}
m.Result = IntPtr.Zero;
NativeMethods.ReleaseDC(m.HWnd,hDC);
}