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.W M_NCPAINT: //0x0085
OnNCPaint(ref m, true);
break;
case NativeMethods.W M_NCACTIVATE://0x0086
OnNCPaint(ref m, (m.WParam.ToInt 32() == 0? false : true) ) ;
break;
default:
break;
}
base.WndProc(re f m);
}
protected void OnNCPaint(ref Message m, bool active)
{
IntPtr hDC = NativeMethods.G etWindowDC(m.HW nd);
if (hDC.ToInt32() == 0)
{
return;
}
using(Graphics g = Graphics.FromHd c(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.R eleaseDC(m.HWnd ,hDC);
} 3 5008
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*******@hotm ail.com> wrote in message
news:9b******** *************** ***@posting.goo gle.com... 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.W M_NCPAINT: //0x0085 OnNCPaint(ref m, true); break; case NativeMethods.W M_NCACTIVATE://0x0086 OnNCPaint(ref m, (m.WParam.ToInt 32() == 0? false : true) ) ; break; default: break; } base.WndProc(re f m); }
protected void OnNCPaint(ref Message m, bool active) { IntPtr hDC = NativeMethods.G etWindowDC(m.HW nd); if (hDC.ToInt32() == 0) { return; }
using(Graphics g = Graphics.FromHd c(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.R eleaseDC(m.HWnd ,hDC); }
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.W M_NCPAINT: //0x0085
base.WndProc(re f 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*******@hotm ail.com> wrote in message
news:9b******** *************** ***@posting.goo gle.com... 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.W M_NCPAINT: //0x0085 OnNCPaint(ref m, true); break; case NativeMethods.W M_NCACTIVATE://0x0086 OnNCPaint(ref m, (m.WParam.ToInt 32() == 0? false : true) ) ; break; default: break; } base.WndProc(re f m); }
protected void OnNCPaint(ref Message m, bool active) { IntPtr hDC = NativeMethods.G etWindowDC(m.HW nd); if (hDC.ToInt32() == 0) { return; }
using(Graphics g = Graphics.FromHd c(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.R eleaseDC(m.HWnd ,hDC); }
"Bob Powell [MVP]" <bob@_spamkille r_bobpowell.net > wrote in message news:<eW******* *******@TK2MSFT NGP14.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.W M_NCPAINT: //0x0085 base.WndProc(re f 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? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Grzesiek |
last post by:
Hello
Is it possible to rotate a non-rectangular region ? Rectangular regions,
created by CreateRectRgn can be rotated using ExtCreateRegion, but how
do the same thing with regions created by CreateEllipticRgn or
CombineRgn? I use Borland C++ Builder
best regards,
Greg
|
by: Julie |
last post by:
How do you retrieve the visible clipping region for a control?
I have a control where I do some on-screen drawing (specifically
ControlPaint.DrawReversibleLine()), however I need to clip the line to the
visible bounds of my control.
Obviously, the client rect is simple enough to retrieve, but what I need to do
is to clip the line segment to only that portion of the control that is
visible, which may _not_ correspond to the client rect...
|
by: BradBrigade |
last post by:
Hi, I created a control deriving from System.Windows.Forms.Control. In
my own OnPaint method, I can draw and set the clipping and everything
is perfect. But I also added some checkboxes by setting their parent
as my control, and I can seem to get them to clip. They just draw
themselves over anything that's under them, right up to the very edge
of the control. How do I get them to clip where I want? Do I set a
property in my control,...
|
by: Martin Wolff |
last post by:
Hi !!
To draw multiple graphics objects which have different shapes, I’m using
the region class to exclude/union the drawing area of these Objects.
The rectangle around a single object is of the size of 80x80 pixels. So
looping through these pixels and excluding the area of every transparent
pixel, the region will be built.
Afterwards, such an object has a memory usage of approx. 700Kb (before
|
by: Mark Denardo |
last post by:
Hi, I need some expert GDI+ person to help me with my RoundOffImage
Function:
What I'm trying to do is take in an image, crop off the edges around an
ellipse region I set up, and then return the cropped image from the
function. I sort of have this working, but not thoroughly.
If I take the output image of this function and draw it on my form it shows
the clipped image as transparent as I am wanting it. But if I take that
image and...
| |
by: peter.chase |
last post by:
In my Web application, a have an image within a DIV. One of the allowed
user gestures is to drag the image with the mouse. When dragging, parts
of the image that would otherwise be displayed outside the DIV should
be clipped.
I had no trouble at all achieving this on FireFox and Safari. But I
can't get Internet Explorer to do the clipping; it always shows the
whole image, including the bits outside the DIV.
Here's the HTML: -
|
by: rlg |
last post by:
Is there a staightforward way of improving the performance of
FillRegion when drawing a very small window on a very large region?
The C# example below illustrates the issue - it takes about 5 seconds
on my 3GHz PC. We also tried using SetClip on the Graphics with
similar results.
If not, do we have to manipulate the PathData directly and is there a
good example?
Thanks in advance...
|
by: Marc |
last post by:
Hi,
I am using the below code which simply allows a single button control
to be dragged and dropped anywhere around a form. My problem is that
want to move about 100 buttons on the form. Is there anyway to modify
the code so that any buttons added on the form will be able to be
dragged and dropped?
Many Thanks!
|
by: Manuel |
last post by:
Hi to all,
I have a System.Drawing.Graphics, I need to clip a region and put it in
a different another Graphics with the size of clipped region.
There's suggestion or a tutorial?
Thanks in advice
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |