From 03269ead9caafb0a6c84c491fc766c0ea4d68da3 Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Sun, 20 Apr 2008 17:45:06 +0000 Subject: [PATCH] Added GetClientRect. Fixed GetWindowLong on 32bit platforms. --- Source/OpenTK/Platform/Windows/API.cs | 54 +++++++++++++++++++-------- 1 file changed, 39 insertions(+), 15 deletions(-) diff --git a/Source/OpenTK/Platform/Windows/API.cs b/Source/OpenTK/Platform/Windows/API.cs index 69365215..a52e1587 100644 --- a/Source/OpenTK/Platform/Windows/API.cs +++ b/Source/OpenTK/Platform/Windows/API.cs @@ -218,6 +218,8 @@ namespace OpenTK.Platform.Windows LPARAM lParam ); + #region SetWindowLong + internal static IntPtr SetWindowLong(IntPtr handle, GetWindowLongOffsets index, IntPtr newValue) { if (IntPtr.Size == 4) @@ -228,28 +230,33 @@ namespace OpenTK.Platform.Windows [SuppressUnmanagedCodeSecurity] [DllImport("user32.dll", SetLastError = true)] - static extern LONG SetWindowLong( - HWND hWnd, - GetWindowLongOffsets nIndex, - LONG dwNewLong - ); + static extern LONG SetWindowLong(HWND hWnd, GetWindowLongOffsets nIndex, LONG dwNewLong); [SuppressUnmanagedCodeSecurity] [DllImport("user32.dll", SetLastError = true)] - static extern LONG_PTR SetWindowLongPtr( - HWND hWnd, - GetWindowLongOffsets nIndex, - LONG_PTR dwNewLong - ); + static extern LONG_PTR SetWindowLongPtr(HWND hWnd, GetWindowLongOffsets nIndex, LONG_PTR dwNewLong); + #endregion + #region GetWindowLong + + internal static IntPtr GetWindowLong(IntPtr handle, GetWindowLongOffsets index) + { + if (IntPtr.Size == 4) + return (IntPtr)GetWindowLongInternal(handle, index); + + return GetWindowLongPtrInternal(handle, index); + } [SuppressUnmanagedCodeSecurity] - [DllImport("user32.dll", SetLastError = true)] - internal static extern LONG_PTR GetWindowLongPtr( - HWND hWnd, - GetWindowLongOffsets nIndex - ); + [DllImport("user32.dll", SetLastError = true, EntryPoint="GetWindowLong")] + static extern LONG GetWindowLongInternal(HWND hWnd, GetWindowLongOffsets nIndex); + + [SuppressUnmanagedCodeSecurity] + [DllImport("user32.dll", SetLastError = true, EntryPoint = "GetWindowLongPtr")] + static extern LONG_PTR GetWindowLongPtrInternal(HWND hWnd, GetWindowLongOffsets nIndex); + + #endregion #endregion @@ -653,6 +660,23 @@ namespace OpenTK.Platform.Windows #endregion + #region GetClientRect + + /// + /// The GetClientRect function retrieves the coordinates of a window's client area. The client coordinates specify the upper-left and lower-right corners of the client area. Because client coordinates are relative to the upper-left corner of a window's client area, the coordinates of the upper-left corner are (0,0). + /// + /// Handle to the window whose client coordinates are to be retrieved. + /// Pointer to a RECT structure that receives the client coordinates. The left and top members are zero. The right and bottom members contain the width and height of the window. + /// + /// If the function succeeds, the return value is nonzero. + /// If the function fails, the return value is zero. To get extended error information, call GetLastError. + /// + /// In conformance with conventions for the RECT structure, the bottom-right coordinates of the returned rectangle are exclusive. In other words, the pixel at (right, bottom) lies immediately outside the rectangle. + [DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity] + internal extern static BOOL GetClientRect(HWND windowHandle, out RECT clientRectangle); + + #endregion + #endregion #region Display settings