private void WmPaint(ref Message m) { // Create a wrapper for the Handle HandleRef myHandle = new HandleRef(this, Handle); // Prepare the window for painting and retrieve a device context NativeMethods.PAINTSTRUCT pAINTSTRUCT = new NativeMethods.PAINTSTRUCT(); IntPtr hDC = UnsafeNativeMethods.BeginPaint(myHandle, ref pAINTSTRUCT); try { // Apply hDC to message m.WParam = hDC; // Let Windows paint base.WndProc(ref m); // Custom painting PaintPrivate(hDC); } finally { // Release the device context that BeginPaint retrieved UnsafeNativeMethods.EndPaint(myHandle, ref pAINTSTRUCT); } }
internal static extern bool EndPaint(HandleRef hWnd, ref NativeMethods.PAINTSTRUCT lpPaint);
internal static extern IntPtr BeginPaint(HandleRef hWnd, [In][Out] ref NativeMethods.PAINTSTRUCT lpPaint);