private void WmPaint(ref Message m) { if (FlatStyle != FlatStyle.System) { return; } IntPtr hWnd = IntPtr.Zero; IntPtr dc; Rectangle clip; NativeMethods.PAINTSTRUCT ps = new NativeMethods.PAINTSTRUCT(); bool needDisposeDC = false; try { if (m.WParam == IntPtr.Zero) { // Cache Handle not only for perf but to avoid object disposed exception in case the window // is destroyed in an event handler (VSW#261657). hWnd = this.Handle; dc = UnsafeNativeMethods.BeginPaint(new HandleRef(this, hWnd), ref ps); if (dc == IntPtr.Zero) { return; } needDisposeDC = true; clip = new Rectangle(ps.rcPaint_left, ps.rcPaint_top, ps.rcPaint_right - ps.rcPaint_left, ps.rcPaint_bottom - ps.rcPaint_top); m_InternalPaint = true; PaintEventArgs pevent = new PaintEventArgs(CreateGraphics(), clip); OnPaint(pevent); } else { dc = m.WParam; clip = ClientRectangle; } } finally { if (needDisposeDC) { UnsafeNativeMethods.EndPaint(new HandleRef(this, hWnd), ref ps); } } }
public static bool EndPaint(HandleRef hWnd, [In, MarshalAs(UnmanagedType.LPStruct)] ref NativeMethods.PAINTSTRUCT lpPaint) { Ekstrand.Internal.HandleCollector.Remove(lpPaint.hdc, NativeMethods.CommonHandles.HDC); return(IntEndPaint(hWnd, ref lpPaint)); }
public static IntPtr BeginPaint(HandleRef hWnd, [In, Out, MarshalAs(UnmanagedType.LPStruct)] ref NativeMethods.PAINTSTRUCT lpPaint) { return(Ekstrand.Internal.HandleCollector.Add(IntBeginPaint(hWnd, ref lpPaint), NativeMethods.CommonHandles.HDC)); }
private static extern bool IntEndPaint(HandleRef hWnd, ref NativeMethods.PAINTSTRUCT lpPaint);
private static extern IntPtr IntBeginPaint(HandleRef hWnd, [In, Out] ref NativeMethods.PAINTSTRUCT lpPaint);