diff --git a/Greenshot/Forms/ImageEditorForm.cs b/Greenshot/Forms/ImageEditorForm.cs index 01987b9af..8959c9e26 100644 --- a/Greenshot/Forms/ImageEditorForm.cs +++ b/Greenshot/Forms/ImageEditorForm.cs @@ -96,7 +96,7 @@ namespace Greenshot { // Make sure the editor is placed on the same location as the last editor was on close WindowDetails thisForm = new WindowDetails(this.Handle); - thisForm.SetWindowPlacement(editorConfiguration.GetEditorPlacement()); + thisForm.WindowPlacement = editorConfiguration.GetEditorPlacement(); // init surface Surface = iSurface; @@ -706,7 +706,7 @@ namespace Greenshot { } } // persist our geometry string. - editorConfiguration.SetEditorPlacement(new WindowDetails(this.Handle).GetWindowPlacement()); + editorConfiguration.SetEditorPlacement(new WindowDetails(this.Handle).WindowPlacement); IniConfig.Save(); // remove from the editor list diff --git a/GreenshotPlugin/Core/WindowsHelper.cs b/GreenshotPlugin/Core/WindowsHelper.cs index 02de583b3..8c7ec42ef 100644 --- a/GreenshotPlugin/Core/WindowsHelper.cs +++ b/GreenshotPlugin/Core/WindowsHelper.cs @@ -771,28 +771,41 @@ namespace GreenshotPlugin.Core { } } + /// + /// Get / Set the WindowStyle + /// public WindowStyleFlags WindowStyle { get { - return (WindowStyleFlags)User32.GetWindowLongWrapper(this.hWnd, (int)WindowLongIndex.GWL_STYLE); + return (WindowStyleFlags)User32.GetWindowLongPtr(this.hWnd, (int)WindowLongIndex.GWL_STYLE); } set { - User32.SetWindowLong(this.hWnd, (int)WindowLongIndex.GWL_STYLE, (uint)value); + User32.SetWindowLongPtr(this.hWnd, (int)WindowLongIndex.GWL_STYLE, (uint)value); } } - public WindowPlacement GetWindowPlacement() { - WindowPlacement placement = WindowPlacement.Default; - User32.GetWindowPlacement(this.Handle, ref placement); - return placement; - } - - public void SetWindowPlacement(WindowPlacement placement) { - User32.SetWindowPlacement(this.Handle, ref placement); + /// + /// Get/Set the WindowPlacement + /// + public WindowPlacement WindowPlacement { + get { + WindowPlacement placement = WindowPlacement.Default; + User32.GetWindowPlacement(this.Handle, ref placement); + return placement; + } + set { + User32.SetWindowPlacement(this.Handle, ref value); + } } + /// + /// Get/Set the Extended WindowStyle + /// public ExtendedWindowStyleFlags ExtendedWindowStyle { get { - return (ExtendedWindowStyleFlags)User32.GetWindowLongWrapper(this.hWnd, (int)WindowLongIndex.GWL_EXSTYLE); + return (ExtendedWindowStyleFlags)User32.GetWindowLongPtr(this.hWnd, (int)WindowLongIndex.GWL_EXSTYLE); + } + set { + User32.SetWindowLongPtr(this.hWnd, (int)WindowLongIndex.GWL_EXSTYLE, (uint)value); } } diff --git a/GreenshotPlugin/UnmanagedHelpers/User32.cs b/GreenshotPlugin/UnmanagedHelpers/User32.cs index 2515a7aeb..7efb531a3 100644 --- a/GreenshotPlugin/UnmanagedHelpers/User32.cs +++ b/GreenshotPlugin/UnmanagedHelpers/User32.cs @@ -114,12 +114,12 @@ namespace GreenshotPlugin.UnmanagedHelpers { public extern static int SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam); [DllImport("user32", SetLastError=true, EntryPoint = "SendMessageA")] public static extern bool SendMessage(IntPtr hWnd, uint msg, int wParam, int lParam); - [DllImport("user32", SetLastError=true)] - public extern static uint GetWindowLong(IntPtr hwnd, int index); + // See: http://msdn.microsoft.com/en-us/library/windows/desktop/ms633585%28v=vs.85%29.aspx [DllImport("user32", EntryPoint="GetWindowLongPtr", SetLastError=true)] public extern static uint GetWindowLongPtr(IntPtr hwnd, int nIndex); - [DllImport("user32", SetLastError = true)] - public static extern int SetWindowLong(IntPtr hWnd, int index, uint styleFlags); + // See: http://msdn.microsoft.com/en-us/library/windows/desktop/ms644898%28v=vs.85%29.aspx + [DllImport("user32", EntryPoint = "SetWindowLongPtr", SetLastError = true)] + public static extern int SetWindowLongPtr(IntPtr hWnd, int index, uint styleFlags); [DllImport("user32", SetLastError = true)] public static extern IntPtr MonitorFromWindow(IntPtr hwnd, uint dwFlags); [DllImport("user32", SetLastError = true)] @@ -221,20 +221,6 @@ namespace GreenshotPlugin.UnmanagedHelpers { [DllImport("user32", SetLastError = true)] public static extern IntPtr CreateIconIndirect(ref IconInfo icon); - /// - /// Wrapper for the GetWindowLong which decides if the system is 64-bit or not and calls the right one. - /// - /// - /// - /// - public static uint GetWindowLongWrapper(IntPtr hwnd, int nIndex) { - if (IntPtr.Size == 8) { - return GetWindowLongPtr(hwnd, nIndex); - } else { - return GetWindowLong(hwnd, nIndex); - } - } - public static uint GetGuiResourcesGDICount() { return GetGuiResources(Process.GetCurrentProcess().Handle, 0); }