From efda1e302597190bdc9e6a031e78599f55eef824 Mon Sep 17 00:00:00 2001 From: RKrom Date: Thu, 20 Dec 2012 14:17:27 +0000 Subject: [PATCH] Fixed WindowLong issue, the MSDN documentation doesn't work for .NET git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2400 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4 --- GreenshotPlugin/Core/WindowsHelper.cs | 8 ++--- GreenshotPlugin/UnmanagedHelpers/User32.cs | 38 +++++++++++++++++++--- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/GreenshotPlugin/Core/WindowsHelper.cs b/GreenshotPlugin/Core/WindowsHelper.cs index 8c7ec42ef..3b1108b6c 100644 --- a/GreenshotPlugin/Core/WindowsHelper.cs +++ b/GreenshotPlugin/Core/WindowsHelper.cs @@ -776,10 +776,10 @@ namespace GreenshotPlugin.Core { /// public WindowStyleFlags WindowStyle { get { - return (WindowStyleFlags)User32.GetWindowLongPtr(this.hWnd, (int)WindowLongIndex.GWL_STYLE); + return (WindowStyleFlags)User32.GetWindowLongWrapper(this.hWnd, (int)WindowLongIndex.GWL_STYLE); } set { - User32.SetWindowLongPtr(this.hWnd, (int)WindowLongIndex.GWL_STYLE, (uint)value); + User32.SetWindowLongWrapper(this.hWnd, (int)WindowLongIndex.GWL_STYLE, (uint)value); } } @@ -802,10 +802,10 @@ namespace GreenshotPlugin.Core { /// public ExtendedWindowStyleFlags ExtendedWindowStyle { get { - return (ExtendedWindowStyleFlags)User32.GetWindowLongPtr(this.hWnd, (int)WindowLongIndex.GWL_EXSTYLE); + return (ExtendedWindowStyleFlags)User32.GetWindowLongWrapper(this.hWnd, (int)WindowLongIndex.GWL_EXSTYLE); } set { - User32.SetWindowLongPtr(this.hWnd, (int)WindowLongIndex.GWL_EXSTYLE, (uint)value); + User32.SetWindowLongWrapper(this.hWnd, (int)WindowLongIndex.GWL_EXSTYLE, (uint)value); } } diff --git a/GreenshotPlugin/UnmanagedHelpers/User32.cs b/GreenshotPlugin/UnmanagedHelpers/User32.cs index 7efb531a3..6c9019e44 100644 --- a/GreenshotPlugin/UnmanagedHelpers/User32.cs +++ b/GreenshotPlugin/UnmanagedHelpers/User32.cs @@ -114,11 +114,13 @@ 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); - // See: http://msdn.microsoft.com/en-us/library/windows/desktop/ms633585%28v=vs.85%29.aspx - [DllImport("user32", EntryPoint="GetWindowLongPtr", SetLastError=true)] + [DllImport("user32", SetLastError = true)] + public extern static uint GetWindowLong(IntPtr hwnd, int index); + [DllImport("user32", SetLastError = true)] public extern static uint GetWindowLongPtr(IntPtr hwnd, int nIndex); - // See: http://msdn.microsoft.com/en-us/library/windows/desktop/ms644898%28v=vs.85%29.aspx - [DllImport("user32", EntryPoint = "SetWindowLongPtr", SetLastError = true)] + [DllImport("user32", SetLastError = true)] + public static extern int SetWindowLong(IntPtr hWnd, int index, uint styleFlags); + [DllImport("user32", 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); @@ -221,6 +223,34 @@ 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); + } + } + + /// + /// Wrapper for the SetWindowLong which decides if the system is 64-bit or not and calls the right one. + /// + /// + /// + /// + public static void SetWindowLongWrapper(IntPtr hwnd, int nIndex, uint styleFlags) { + if (IntPtr.Size == 8) { + SetWindowLongPtr(hwnd, nIndex, styleFlags); + } else { + SetWindowLong(hwnd, nIndex, styleFlags); + } + } + public static uint GetGuiResourcesGDICount() { return GetGuiResources(Process.GetCurrentProcess().Handle, 0); }