Modifying clip region

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);
}
 
D

Dan Bass

I've done the same thing, but don't bother hooking into the native windows
methods... Simply create a panel that fills the dialog, then has a border.
Then the title bar is a label. Image buttons can be placed onto this etc.

Maybe this is the lazy and improper way (?) but it works a treat.

Thanks.

Dan.
 
B

Bob Powell [MVP]

You should call the base WndProc before Defaultyou paint your stuff such as:

protected override void WndProc(ref Message m)
{
switch(m.Msg)
{
case NativeMethods.WM_NCPAINT: //0x0085
base.WndProc(ref m); // paint all the standard stuff
OnNCPaint(ref m, true); //then your own gubbins
break;
//other cases as needed....
default:
base.DefWndProc(ref m);
break;
}
}

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
M

Martin

Bob Powell said:
You should call the base WndProc before Defaultyou paint your stuff such as:

protected override void WndProc(ref Message m)
{
switch(m.Msg)
{
case NativeMethods.WM_NCPAINT: //0x0085
base.WndProc(ref m); // paint all the standard stuff
OnNCPaint(ref m, true); //then your own gubbins
break;
//other cases as needed....
default:
base.DefWndProc(ref m);
break;
}
}
Well if I call base.WndProc first then I'll get lots of flickering
since windows is painting with the standard blue and then I'm painting
over it. Surely it must be possible to modifying the clip region so
windows won't paint in that area at all?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top