By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,743 Members | 1,018 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,743 IT Pros & Developers. It's quick & easy.

Modifying clip region

P: n/a
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);
}
Nov 16 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a

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.

"Martin" <pe*******@hotmail.com> wrote in message
news:9b**************************@posting.google.c om...
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);
}

Nov 16 '05 #2

P: n/a
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.

"Martin" <pe*******@hotmail.com> wrote in message
news:9b**************************@posting.google.c om...
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);
}

Nov 16 '05 #3

P: n/a
"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message news:<eW**************@TK2MSFTNGP14.phx.gbl>...
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?
Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.