From d76c7b3efc3a64dead6f23cb141ae58f10f54269 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Wed, 3 Dec 2014 18:23:04 +0100 Subject: [PATCH] Fixed the problem with WM_PAINT. Need to call Begin/EndPaint. --- .../Perspex.Win32/Interop/UnmanagedMethods.cs | 3 ++ Windows/Perspex.Win32/WindowImpl.cs | 34 +++++++++---------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/Windows/Perspex.Win32/Interop/UnmanagedMethods.cs b/Windows/Perspex.Win32/Interop/UnmanagedMethods.cs index 001fef6489..c295080738 100644 --- a/Windows/Perspex.Win32/Interop/UnmanagedMethods.cs +++ b/Windows/Perspex.Win32/Interop/UnmanagedMethods.cs @@ -377,6 +377,9 @@ namespace Perspex.Win32.Interop [DllImport("user32.dll", SetLastError = true)] public static extern bool DestroyWindow(IntPtr hwnd); + [DllImport("user32.dll")] + public static extern bool EndPaint(IntPtr hWnd, ref PAINTSTRUCT lpPaint); + [DllImport("user32.dll")] public static extern uint GetCaretBlinkTime(); diff --git a/Windows/Perspex.Win32/WindowImpl.cs b/Windows/Perspex.Win32/WindowImpl.cs index 7065d9f760..3af2c0667e 100644 --- a/Windows/Perspex.Win32/WindowImpl.cs +++ b/Windows/Perspex.Win32/WindowImpl.cs @@ -59,16 +59,15 @@ namespace Perspex.Win32 public void Invalidate(Rect rect) { - this.Paint(rect, this.Handle); - //var r = new UnmanagedMethods.RECT - //{ - // left = (int)rect.X, - // top = (int)rect.Y, - // right = (int)rect.Right, - // bottom = (int)rect.Bottom, - //}; - - //UnmanagedMethods.InvalidateRect(this.hwnd, ref r, false); + var r = new UnmanagedMethods.RECT + { + left = (int)rect.X, + top = (int)rect.Y, + right = (int)rect.Right, + bottom = (int)rect.Bottom, + }; + + UnmanagedMethods.InvalidateRect(this.hwnd, ref r, false); } public void SetOwner(Window owner) @@ -185,13 +184,14 @@ namespace Perspex.Win32 new Point((uint)lParam & 0xffff, (uint)lParam >> 16)); break; - // TODO: For some reason WM_PAINT getting called continuously - investigate. - - //case UnmanagedMethods.WindowsMessage.WM_PAINT: - // UnmanagedMethods.RECT r; - // UnmanagedMethods.GetUpdateRect(this.hwnd, out r, false); - // this.Paint(new Rect(r.left, r.top, r.right - r.left, r.bottom - r.top)); - // return IntPtr.Zero; + case UnmanagedMethods.WindowsMessage.WM_PAINT: + UnmanagedMethods.RECT r; + UnmanagedMethods.PAINTSTRUCT ps; + UnmanagedMethods.GetUpdateRect(this.hwnd, out r, false); + UnmanagedMethods.BeginPaint(this.hwnd, out ps); + this.Paint(new Rect(r.left, r.top, r.right - r.left, r.bottom - r.top), this.Handle); + UnmanagedMethods.EndPaint(this.hwnd, ref ps); + return IntPtr.Zero; case UnmanagedMethods.WindowsMessage.WM_SIZE: if (this.Resized != null)