From fb82df5ff8665e407f2fcf42a3c6a825acf2755b Mon Sep 17 00:00:00 2001 From: Chris Kaczor Date: Fri, 23 Oct 2015 20:20:25 -0400 Subject: [PATCH] More Win32 support --- Constants.cs | 29 ++++++++++++++++++++++++++++- Functions.cs | 24 ++++++++++++++++++++++-- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/Constants.cs b/Constants.cs index 3b9197a..f5066c1 100644 --- a/Constants.cs +++ b/Constants.cs @@ -138,13 +138,40 @@ namespace Common.Native } [Flags] - public enum ExtendedWindowStyles + public enum WindowStyles : uint { + Overlapped = 0x00000000, + Caption = 0x00C00000, + SystemMenu = 0x00080000, + ThickFrame = 0x00040000, + MinimizeBox = 0x00020000, + MaximizeBox = 0x00010000, + Visible = 0x10000000, + Child = 0x40000000, + Popup = 0x80000000, + OverlappedWindow = Overlapped | Caption | SystemMenu | ThickFrame | MinimizeBox | MaximizeBox + } + + [Flags] + public enum ExtendedWindowStyles : long + { + DialogModalFrame = 0x00000001, ToolWindow = 0x00000080, + AppWindow = 0x00040000, + WindowEdge = 0x00000100, + ClientEdge = 0x00000200, + OverlappedWindow = WindowEdge | ClientEdge + } + + public enum GetWindowFields + { + Owner = 4 } public enum GetWindowLongFields { + Parent = -8, + Style = -16, ExStyle = -20, } diff --git a/Functions.cs b/Functions.cs index e2e8820..d6fb352 100644 --- a/Functions.cs +++ b/Functions.cs @@ -139,6 +139,9 @@ namespace Common.Native [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount); + [DllImport("user32.dll", SetLastError = true)] + public static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId); + [DllImport("user32.dll", CharSet = CharSet.Auto)] public static extern IntPtr SendMessage(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam); @@ -148,8 +151,11 @@ namespace Common.Native [DllImport("user32.dll", ExactSpelling = true, CharSet = CharSet.Auto)] public static extern IntPtr GetParent(IntPtr hWnd); + [DllImport("user32", CharSet = CharSet.Auto, SetLastError = true, ExactSpelling = true)] + public static extern IntPtr GetWindow(IntPtr hwnd, int wFlag); + [DllImport("user32.dll")] - public static extern IntPtr GetWindowLong(IntPtr hWnd, int nIndex); + public static extern long GetWindowLong(IntPtr hWnd, Constants.GetWindowLongFields nIndex); [DllImport("user32.dll")] public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong); @@ -163,6 +169,10 @@ namespace Common.Native [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] public static extern uint RegisterWindowMessage(string lpString); + [DllImport("user32.dll")] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool IsWindowVisible(IntPtr hWnd); + public static IntPtr SetWindowLongPtrSmart(IntPtr hWnd, int nIndex, IntPtr dwNewLong) { if (IntPtr.Size == 8) @@ -181,9 +191,19 @@ namespace Common.Native { if (IntPtr.Size > 4) return GetClassLongPtr64(hWnd, nIndex); - + return new IntPtr(GetClassLongPtr32(hWnd, nIndex)); } + + public static bool HasStyle(long windowStyle, Constants.WindowStyles checkStyle) + { + return ((windowStyle & (long) checkStyle) == (long) checkStyle); + } + + public static bool HasExtendedStyle(long windowStyle, Constants.ExtendedWindowStyles checkStyle) + { + return ((windowStyle & (long) checkStyle) == (long) checkStyle); + } } public static class Kernel32