public
static IntPtr GetDC(Message msg)
{
if (msg.Msg != (int)WindowMessages.WM_NCPAINT)
{
return GetWindowDC(msg.HWnd);
}
int flags = (int)(DCX.DCX_CACHE | DCX.DCX_CLIPSIBLINGS | DCX.DCX_WINDOW );
IntPtr zero = IntPtr.Zero;
if (msg.WParam.ToInt32() != 1)
{
flags |= (
int)DCX.DCX_INTERSECTRGN;
zero = msg.WParam;
}
return GetDCEx(msg.HWnd, zero, flags);
}
3 Answers, 1 is accepted
Thank you for writing.
I am afraid that I do not understand where the problem is. Can you elaborate a bit on your code? Thank you very much in advance.
Regards,
Nick
the Telerik team
Check out Telerik Trainer , the state of the art learning tool for Telerik products.
The DefWindowProc function paints the window frame.
An application can intercept the WM_NCPAINT message and paint its own custom window frame. The clipping region for a window is always rectangular, even if the shape of the frame is altered.
The wParam value can be passed to GetDCEx as in the following example.
case WM_NCPAINT: { HDC hdc; hdc = GetDCEx(hwnd, (HRGN)wParam, DCX_WINDOW|DCX_INTERSECTRGN); // Paint into this DC ReleaseDC(hwnd, hdc); }First off ---- The update region is clipped to the window frame. When wParam is 1, the entire window frame
needs to be updated. How you got it is the same as MSDN states it. This is for use when the wParam not
equal 1. If the wParam equals 1 the entire window frame needs to be updated. So you don't need
DCX_INTERSECTRGN when it equals 1. So the piece of code thats on this page was used for in a project of
mines. So I want to share somthing that I had problems with and I see that your team got now. Here is a
piece of code to go about it (example)...All of this is done on a subclass of a System.Windows.Forms.Form.
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case (int)WindowMessages.WM_NCPAINT: //0x85
WmNCPaint(ref m);
break;
default:
base.WndProc(ref m);
break;
}
}
private void WmNCPaint(ref Message msg)
{RECT windowRect = new RECT();
if (GetWindowRect(msg.HWnd, ref windowRect) == false)
return;Rectangle bounds = new Rectangle(0, 0,
windowRect.right - windowRect.left,
windowRect.bottom - windowRect.top);if (bounds.Width == 0 || bounds.Height == 0)
return;// retrieves the device context (DC) for the entire window,
// including title bar, menus, and scroll bars
IntPtr hDC = GetDC(msg);
if (hDC == IntPtr.Zero)
return;// assign clip region to exclude client area
Rectangle clientRect = ExcludePadding(bounds, this.ClientAreaOffSet);
ExcludeClipRect(hDC, clientRect.Left, clientRect.Top, clientRect.Right, clientRect.Bottom);
try
{
// Double-buffering technique the old way
IntPtr CompatiblehDC = CreateCompatibleDC(hDC);
IntPtr CompatibleBitmap = CreateCompatibleBitmap(hDC, bounds.Width, bounds.Height);try
{
SelectObject(CompatiblehDC, CompatibleBitmap);using (Graphics g = Graphics.FromHdc(CompatiblehDC))
{
// Do your drawing here.
}// copy current bitmap to screen, blast bits to screen
BitBlt(hDC, 0, 0, bounds.Width, bounds.Height, CompatiblehDC, 0, 0, 0x00CC0020/*SRCCOPY*/);
//goto Label_0178;
}
finally
{
DeleteObject(CompatibleBitmap);
DeleteDC(CompatiblehDC);
}
}
finally
{
//DeleteObject(hrgnClip);
ReleaseDC(msg.HWnd, hDC);
}//Label_0178:
// we handled everything MSDN states that an application returns zero if it processes
// this message.
msg.Result = ((IntPtr)0);
}
public static IntPtr GetDC(Message msg)
{if (msg.Msg != (int)WindowMessages.WM_NCPAINT)
{
return GetWindowDC(msg.HWnd);
}
int flags = (int)(DCX.DCX_CACHE | DCX.DCX_CLIPSIBLINGS
| DCX.DCX_WINDOW );IntPtr zero = IntPtr.Zero;
if (msg.WParam.ToInt32() != 1)
{
flags |= (int)DCX.DCX_INTERSECTRGN;//0x80;
zero = msg.WParam;
}
// check out http://www.codeproject.com/KB/GDI/updatergn.aspx on GetDCEx
// the best I seen so far on this
return GetDCEx(msg.HWnd, zero, flags);
}Still need to elaborate a lit bit more just post.
Thanks for your response and for the details provided.
I would like to inform you that we are going to investigate the code that you provided and we are also going to update our code according to the requirements if needed.
I have updated your Telerik points for pointing this out to us.
Regards,
Deyan
the Telerik team
Check out Telerik Trainer , the state of the art learning tool for Telerik products.