GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
refactor: moved all windows api models and services to new Common directory
Lars1ec89055c4f2
diff --git a/LarsWM/WindowsApi/DataTypes/SetWindowPosFlags.cs b/LarsWM/Common/Models/SetWindowPosFlags.cssimilarity index 100%rename from LarsWM/WindowsApi/DataTypes/SetWindowPosFlags.csrename to LarsWM/Common/Models/SetWindowPosFlags.csdiff --git a/LarsWM/WindowLocation.cs b/LarsWM/Common/Models/WindowLocation.cssimilarity index 100%rename from LarsWM/WindowLocation.csrename to LarsWM/Common/Models/WindowLocation.csdiff --git a/LarsWM/WindowsApi/DataTypes/WindowRect.cs b/LarsWM/Common/Models/WindowRect.cssimilarity index 100%rename from LarsWM/WindowsApi/DataTypes/WindowRect.csrename to LarsWM/Common/Models/WindowRect.csdiff --git a/LarsWM/WindowsApi/WindowsApiFacade.cs b/LarsWM/Common/Services/WindowsApiFacade.cssimilarity index 96%rename from LarsWM/WindowsApi/WindowsApiFacade.csrename to LarsWM/Common/Services/WindowsApiFacade.csindex 3223ab15..f6089fa0 100644--- a/LarsWM/WindowsApi/WindowsApiFacade.cs+++ b/LarsWM/Common/Services/WindowsApiFacade.cs@@ -1,146 +1,146 @@-using System;-using System.Collections.Generic;-using System.Diagnostics;-using System.Linq;-using System.Text;-using System.Runtime.InteropServices;-using static LarsWM.WindowsApi.WindowsApiService;-using static LarsWM.UserConfig.UserConfigService;-using LarsWM.WindowsApi.DataTypes;--namespace LarsWM.WindowsApi-{- class WindowsApiFacade- {- public static Window[] GetOpenWindows()- {- var shellWindow = GetShellWindow();-- Predicate<Window> OpenWindowsPredicate = (Window window) => {- var isApplicationWindow = IsWindowVisible(window.Hwnd) && !HasWindowStyle(window.Hwnd, WS.WS_CHILD) && !HasWindowExStyle(window.Hwnd, WS_EX.WS_EX_NOACTIVATE);-- var isCurrentProcess = window.Process.Id == Process.GetCurrentProcess().Id;-- var isExcludedClassName = WindowClassesToIgnore.Contains(window.ClassName);- var isExcludedProcessName = ProcessNamesToIgnore.Contains(window.Process.ProcessName);-- var isShellWindow = window.Hwnd == shellWindow;-- if (isApplicationWindow && !isCurrentProcess && !isExcludedClassName && !isExcludedProcessName && !isShellWindow)- {- return true;- }-- return false;- };-- return FilterToplevelWindows(OpenWindowsPredicate);- }-- /// <summary>- /// Returns all top-level windows that match the given predicate.- /// </summary>- /// <param name="predicate">The predicate to filter by.</param>- public static Window[] FilterToplevelWindows(Predicate<Window> predicate)- {- List<Window> matchedWindows = new List<Window>();-- EnumWindows(new EnumWindowsDelegate(delegate (IntPtr hwnd, int lParam)- {- Window window = new Window(hwnd);-- if (predicate(window))- {- matchedWindows.Add(window);- }- return true;- }), new IntPtr(0));-- return matchedWindows.ToArray();- }-- /// <summary>- /// Get the id of the process that created the window.- /// </summary>- public static Process GetProcessOfWindow(Window window)- {- uint processId;- GetWindowThreadProcessId(window.Hwnd, out processId);-- try- {- return Process.GetProcesses().First(process => process.Id == (int)processId);- } catch(InvalidOperationException)- {- return null;- }- }-- /// <summary>- /// Get the name of the class of the window.- /// </summary>- public static string GetClassNameOfWindow(Window window)- {- var buffer = new StringBuilder(255);- GetClassName(window.Hwnd, buffer, buffer.Capacity + 1);- return buffer.ToString();- }--- /// <summary>- /// Get dimensions of the bounding rectangle of the specified window.- /// </summary>- public static WindowRect GetLocationOfWindow(Window window)- {- WindowRect rect = new WindowRect();- GetWindowRect(window.Hwnd, ref rect);- return rect;- }-- public static bool HasWindowStyle(IntPtr hwnd, WS style)- {- var styles = unchecked((WS)GetWindowLongPtr(hwnd, (int)(GWL_STYLE)).ToInt64());-- return (styles & style) != 0;- }-- public static bool HasWindowExStyle(IntPtr hwnd, WS_EX style)- {- var styles = unchecked((WS_EX)GetWindowLongPtr(hwnd, (int)(GWL_EXSTYLE)).ToInt64());-- return (styles & style) != 0;- }-- private static IntPtr GetWindowLongPtr(IntPtr hWnd, int nIndex)- {- if (Environment.Is64BitProcess)- {- return GetWindowLongPtr64(hWnd, nIndex);- }- else- {- return new IntPtr(GetWindowLong32(hWnd, nIndex));- }- }-- public static bool IsWindowCloaked(Window window)- {-- bool isCloaked;- DwmGetWindowAttribute(window.Hwnd, DwmWindowAttribute.DWMWA_CLOAKED, out isCloaked, Marshal.SizeOf(typeof(bool)));- return isCloaked;- }-- public static bool IsWindowManageable(Window window)- {-- if (HasWindowExStyle(window.Hwnd, WS_EX.WS_EX_TOOLWINDOW) ||- GetWindow(window.Hwnd, GW.GW_OWNER) != IntPtr.Zero)- {- return false;- }-- return true;- }- }-}+using System;+using System.Collections.Generic;+using System.Diagnostics;+using System.Linq;+using System.Text;+using System.Runtime.InteropServices;+using static LarsWM.WindowsApi.WindowsApiService;+using static LarsWM.UserConfig.UserConfigService;+using LarsWM.WindowsApi.DataTypes;++namespace LarsWM.WindowsApi+{+ class WindowsApiFacade+ {+ public static Window[] GetOpenWindows()+ {+ var shellWindow = GetShellWindow();++ Predicate<Window> OpenWindowsPredicate = (Window window) => {+ var isApplicationWindow = IsWindowVisible(window.Hwnd) && !HasWindowStyle(window.Hwnd, WS.WS_CHILD) && !HasWindowExStyle(window.Hwnd, WS_EX.WS_EX_NOACTIVATE);++ var isCurrentProcess = window.Process.Id == Process.GetCurrentProcess().Id;++ var isExcludedClassName = WindowClassesToIgnore.Contains(window.ClassName);+ var isExcludedProcessName = ProcessNamesToIgnore.Contains(window.Process.ProcessName);++ var isShellWindow = window.Hwnd == shellWindow;++ if (isApplicationWindow && !isCurrentProcess && !isExcludedClassName && !isExcludedProcessName && !isShellWindow)+ {+ return true;+ }++ return false;+ };++ return FilterToplevelWindows(OpenWindowsPredicate);+ }++ /// <summary>+ /// Returns all top-level windows that match the given predicate.+ /// </summary>+ /// <param name="predicate">The predicate to filter by.</param>+ public static Window[] FilterToplevelWindows(Predicate<Window> predicate)+ {+ List<Window> matchedWindows = new List<Window>();++ EnumWindows(new EnumWindowsDelegate(delegate (IntPtr hwnd, int lParam)+ {+ Window window = new Window(hwnd);++ if (predicate(window))+ {+ matchedWindows.Add(window);+ }+ return true;+ }), new IntPtr(0));++ return matchedWindows.ToArray();+ }++ /// <summary>+ /// Get the id of the process that created the window.+ /// </summary>+ public static Process GetProcessOfWindow(Window window)+ {+ uint processId;+ GetWindowThreadProcessId(window.Hwnd, out processId);++ try+ {+ return Process.GetProcesses().First(process => process.Id == (int)processId);+ } catch(InvalidOperationException)+ {+ return null;+ }+ }++ /// <summary>+ /// Get the name of the class of the window.+ /// </summary>+ public static string GetClassNameOfWindow(Window window)+ {+ var buffer = new StringBuilder(255);+ GetClassName(window.Hwnd, buffer, buffer.Capacity + 1);+ return buffer.ToString();+ }+++ /// <summary>+ /// Get dimensions of the bounding rectangle of the specified window.+ /// </summary>+ public static WindowRect GetLocationOfWindow(Window window)+ {+ WindowRect rect = new WindowRect();+ GetWindowRect(window.Hwnd, ref rect);+ return rect;+ }++ public static bool HasWindowStyle(IntPtr hwnd, WS style)+ {+ var styles = unchecked((WS)GetWindowLongPtr(hwnd, (int)(GWL_STYLE)).ToInt64());++ return (styles & style) != 0;+ }++ public static bool HasWindowExStyle(IntPtr hwnd, WS_EX style)+ {+ var styles = unchecked((WS_EX)GetWindowLongPtr(hwnd, (int)(GWL_EXSTYLE)).ToInt64());++ return (styles & style) != 0;+ }++ private static IntPtr GetWindowLongPtr(IntPtr hWnd, int nIndex)+ {+ if (Environment.Is64BitProcess)+ {+ return GetWindowLongPtr64(hWnd, nIndex);+ }+ else+ {+ return new IntPtr(GetWindowLong32(hWnd, nIndex));+ }+ }++ public static bool IsWindowCloaked(Window window)+ {++ bool isCloaked;+ DwmGetWindowAttribute(window.Hwnd, DwmWindowAttribute.DWMWA_CLOAKED, out isCloaked, Marshal.SizeOf(typeof(bool)));+ return isCloaked;+ }++ public static bool IsWindowManageable(Window window)+ {++ if (HasWindowExStyle(window.Hwnd, WS_EX.WS_EX_TOOLWINDOW) ||+ GetWindow(window.Hwnd, GW.GW_OWNER) != IntPtr.Zero)+ {+ return false;+ }++ return true;+ }+ }+}diff --git a/LarsWM/WindowsApi/WindowsApiService.cs b/LarsWM/Common/Services/WindowsApiService.cssimilarity index 97%rename from LarsWM/WindowsApi/WindowsApiService.csrename to LarsWM/Common/Services/WindowsApiService.csindex 7bb52108..9c875cc2 100644--- a/LarsWM/WindowsApi/WindowsApiService.cs+++ b/LarsWM/Common/Services/WindowsApiService.cs@@ -1,183 +1,183 @@-using LarsWM.WindowsApi.DataTypes;-using System;-using System.Collections.Generic;-using System.Runtime.InteropServices;-using System.Text;--namespace LarsWM.WindowsApi-{- class WindowsApiService- {- public enum SWP : uint- {- SWP_SHOWWINDOW = 0x0040,- SWP_HIDEWINDOW = 0x0080,- SWP_NOZORDER = 0x0004,- SWP_NOREDRAW = 0x0008,- SWP_NOACTIVATE = 0x0010,- SWP_NOMOVE = 0x0002,- SWP_NOSIZE = 0x0001,- SWP_FRAMECHANGED = 0x0020,- SWP_NOCOPYBITS = 0x0100,- SWP_NOOWNERZORDER = 0x0200,- SWP_DEFERERASE = 0x2000,- SWP_NOSENDCHANGING = 0x0400,- SWP_ASYNCWINDOWPOS = 0x4000- }-- /// <summary>- /// Window styles- /// </summary>- [Flags]- public enum WS : int- {- WS_OVERLAPPED = 0,- WS_POPUP = unchecked((int)0x80000000),- WS_CHILD = 0x40000000,- WS_MINIMIZE = 0x20000000,- WS_VISIBLE = 0x10000000,- WS_DISABLED = 0x8000000,- WS_CLIPSIBLINGS = 0x4000000,- WS_CLIPCHILDREN = 0x2000000,- WS_MAXIMIZE = 0x1000000,- WS_CAPTION = WS_BORDER | WS_DLGFRAME,- WS_BORDER = 0x800000,- WS_DLGFRAME = 0x400000,- WS_VSCROLL = 0x200000,- WS_HSCROLL = 0x100000,- WS_SYSMENU = 0x80000,- WS_THICKFRAME = 0x40000,- WS_MINIMIZEBOX = 0x20000,- WS_MAXIMIZEBOX = 0x10000,- WS_TILED = WS_OVERLAPPED,- WS_ICONIC = WS_MINIMIZE,- WS_SIZEBOX = WS_THICKFRAME,- WS_OVERLAPPEDWINDOW = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX- }-- /// <summary>- /// Extended window styles- /// </summary>- [Flags]- public enum WS_EX : uint- {- WS_EX_DLGMODALFRAME = 0x0001,- WS_EX_NOPARENTNOTIFY = 0x0004,- WS_EX_TOPMOST = 0x0008,- WS_EX_ACCEPTFILES = 0x0010,- WS_EX_TRANSPARENT = 0x0020,- WS_EX_MDICHILD = 0x0040,- WS_EX_TOOLWINDOW = 0x0080,- WS_EX_WINDOWEDGE = 0x0100,- WS_EX_CLIENTEDGE = 0x0200,- WS_EX_CONTEXTHELP = 0x0400,- WS_EX_RIGHT = 0x1000,- WS_EX_LEFT = 0x0000,- WS_EX_RTLREADING = 0x2000,- WS_EX_LTRREADING = 0x0000,- WS_EX_LEFTSCROLLBAR = 0x4000,- WS_EX_RIGHTSCROLLBAR = 0x0000,- WS_EX_CONTROLPARENT = 0x10000,- WS_EX_STATICEDGE = 0x20000,- WS_EX_APPWINDOW = 0x40000,- WS_EX_OVERLAPPEDWINDOW = (WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE),- WS_EX_PALETTEWINDOW = (WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW | WS_EX_TOPMOST),- WS_EX_LAYERED = 0x00080000,- WS_EX_NOINHERITLAYOUT = 0x00100000,- WS_EX_LAYOUTRTL = 0x00400000,- WS_EX_COMPOSITED = 0x02000000,- WS_EX_NOACTIVATE = 0x08000000- }-- [Flags]- public enum DwmWindowAttribute : uint- {- DWMWA_NCRENDERING_ENABLED = 1,- DWMWA_NCRENDERING_POLICY,- DWMWA_TRANSITIONS_FORCEDISABLED,- DWMWA_ALLOW_NCPAINT,- DWMWA_CAPTION_BUTTON_BOUNDS,- DWMWA_NONCLIENT_RTL_LAYOUT,- DWMWA_FORCE_ICONIC_REPRESENTATION,- DWMWA_FLIP3D_POLICY,- DWMWA_EXTENDED_FRAME_BOUNDS,- DWMWA_HAS_ICONIC_BITMAP,- DWMWA_DISALLOW_PEEK,- DWMWA_EXCLUDED_FROM_PEEK,- DWMWA_CLOAK,- DWMWA_CLOAKED,- DWMWA_FREEZE_REPRESENTATION,- DWMWA_LAST- }-- public static int GWL_STYLE = -16;- public static int GWL_EXSTYLE = -20;-- public enum GW : uint- {- GW_OWNER = 4,- }-- public delegate bool EnumWindowsDelegate(IntPtr hWnd, int lParam);-- [DllImport("user32.dll", EntryPoint = "EnumWindows", ExactSpelling = false, CharSet = CharSet.Auto, SetLastError = true)]- public static extern bool EnumWindows(EnumWindowsDelegate enumCallback, IntPtr lParam);-- [DllImport("user32.dll")]- [return: MarshalAs(UnmanagedType.Bool)]- public static extern bool IsWindowVisible(IntPtr hWnd);-- [DllImport("user32.dll", EntryPoint = "GetWindowLong")]- public static extern int GetWindowLong32(IntPtr hWnd, int nIndex);-- [DllImport("user32.dll", EntryPoint = "GetWindowLongPtr")]- public static extern IntPtr GetWindowLongPtr64(IntPtr hWnd, int nIndex);-- [DllImport("user32.dll")]- public static extern IntPtr BeginDeferWindowPos(int nNumWindows);-- [DllImport("user32.dll")]- public static extern IntPtr DeferWindowPos(IntPtr hWinPosInfo, IntPtr hWnd,- [Optional] IntPtr hWndInsertAfter, int x, int y, int cx, int cy, SWP uFlags);-- [DllImport("user32.dll")]- [return: MarshalAs(UnmanagedType.Bool)]- public static extern bool EndDeferWindowPos(IntPtr hWinPosInfo);-- [DllImport("user32.dll")]- public static extern IntPtr GetForegroundWindow();-- [DllImport("user32.dll")]- public static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);-- [DllImport("user32.dll")]- public static extern bool SetFocus(IntPtr hWnd);-- [DllImport("user32.dll")]- public static extern bool ShowWindow(IntPtr hWnd, int X);-- [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]- public static extern int GetWindowTextLength(IntPtr hWnd);-- [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]- public static extern int GetWindowText(IntPtr hWnd, [Out] StringBuilder lpString, int nMaxCount);-- [DllImport("user32.dll", SetLastError=true)]- public static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);-- [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]- public static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName,int nMaxCount);-- [DllImport("user32.dll")]- public static extern bool GetWindowRect(IntPtr hwnd, ref WindowRect rectangle);-- [DllImport("user32.dll")]- public static extern IntPtr GetWindow(IntPtr hWnd, GW uCmd);-- [DllImport("dwmapi.dll")]- public static extern int DwmGetWindowAttribute(IntPtr hwnd, DwmWindowAttribute dwAttribute, out bool pvAttribute, int cbAttribute);-- [DllImport("user32.dll")]- public static extern IntPtr GetShellWindow();- }-}+using LarsWM.WindowsApi.DataTypes;+using System;+using System.Collections.Generic;+using System.Runtime.InteropServices;+using System.Text;++namespace LarsWM.WindowsApi+{+ class WindowsApiService+ {+ public enum SWP : uint+ {+ SWP_SHOWWINDOW = 0x0040,+ SWP_HIDEWINDOW = 0x0080,+ SWP_NOZORDER = 0x0004,+ SWP_NOREDRAW = 0x0008,+ SWP_NOACTIVATE = 0x0010,+ SWP_NOMOVE = 0x0002,+ SWP_NOSIZE = 0x0001,+ SWP_FRAMECHANGED = 0x0020,+ SWP_NOCOPYBITS = 0x0100,+ SWP_NOOWNERZORDER = 0x0200,+ SWP_DEFERERASE = 0x2000,+ SWP_NOSENDCHANGING = 0x0400,+ SWP_ASYNCWINDOWPOS = 0x4000+ }++ /// <summary>+ /// Window styles+ /// </summary>+ [Flags]+ public enum WS : int+ {+ WS_OVERLAPPED = 0,+ WS_POPUP = unchecked((int)0x80000000),+ WS_CHILD = 0x40000000,+ WS_MINIMIZE = 0x20000000,+ WS_VISIBLE = 0x10000000,+ WS_DISABLED = 0x8000000,+ WS_CLIPSIBLINGS = 0x4000000,+ WS_CLIPCHILDREN = 0x2000000,+ WS_MAXIMIZE = 0x1000000,+ WS_CAPTION = WS_BORDER | WS_DLGFRAME,+ WS_BORDER = 0x800000,+ WS_DLGFRAME = 0x400000,+ WS_VSCROLL = 0x200000,+ WS_HSCROLL = 0x100000,+ WS_SYSMENU = 0x80000,+ WS_THICKFRAME = 0x40000,+ WS_MINIMIZEBOX = 0x20000,+ WS_MAXIMIZEBOX = 0x10000,+ WS_TILED = WS_OVERLAPPED,+ WS_ICONIC = WS_MINIMIZE,+ WS_SIZEBOX = WS_THICKFRAME,+ WS_OVERLAPPEDWINDOW = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX+ }++ /// <summary>+ /// Extended window styles+ /// </summary>+ [Flags]+ public enum WS_EX : uint+ {+ WS_EX_DLGMODALFRAME = 0x0001,+ WS_EX_NOPARENTNOTIFY = 0x0004,+ WS_EX_TOPMOST = 0x0008,+ WS_EX_ACCEPTFILES = 0x0010,+ WS_EX_TRANSPARENT = 0x0020,+ WS_EX_MDICHILD = 0x0040,+ WS_EX_TOOLWINDOW = 0x0080,+ WS_EX_WINDOWEDGE = 0x0100,+ WS_EX_CLIENTEDGE = 0x0200,+ WS_EX_CONTEXTHELP = 0x0400,+ WS_EX_RIGHT = 0x1000,+ WS_EX_LEFT = 0x0000,+ WS_EX_RTLREADING = 0x2000,+ WS_EX_LTRREADING = 0x0000,+ WS_EX_LEFTSCROLLBAR = 0x4000,+ WS_EX_RIGHTSCROLLBAR = 0x0000,+ WS_EX_CONTROLPARENT = 0x10000,+ WS_EX_STATICEDGE = 0x20000,+ WS_EX_APPWINDOW = 0x40000,+ WS_EX_OVERLAPPEDWINDOW = (WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE),+ WS_EX_PALETTEWINDOW = (WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW | WS_EX_TOPMOST),+ WS_EX_LAYERED = 0x00080000,+ WS_EX_NOINHERITLAYOUT = 0x00100000,+ WS_EX_LAYOUTRTL = 0x00400000,+ WS_EX_COMPOSITED = 0x02000000,+ WS_EX_NOACTIVATE = 0x08000000+ }++ [Flags]+ public enum DwmWindowAttribute : uint+ {+ DWMWA_NCRENDERING_ENABLED = 1,+ DWMWA_NCRENDERING_POLICY,+ DWMWA_TRANSITIONS_FORCEDISABLED,+ DWMWA_ALLOW_NCPAINT,+ DWMWA_CAPTION_BUTTON_BOUNDS,+ DWMWA_NONCLIENT_RTL_LAYOUT,+ DWMWA_FORCE_ICONIC_REPRESENTATION,+ DWMWA_FLIP3D_POLICY,+ DWMWA_EXTENDED_FRAME_BOUNDS,+ DWMWA_HAS_ICONIC_BITMAP,+ DWMWA_DISALLOW_PEEK,+ DWMWA_EXCLUDED_FROM_PEEK,+ DWMWA_CLOAK,+ DWMWA_CLOAKED,+ DWMWA_FREEZE_REPRESENTATION,+ DWMWA_LAST+ }++ public static int GWL_STYLE = -16;+ public static int GWL_EXSTYLE = -20;++ public enum GW : uint+ {+ GW_OWNER = 4,+ }++ public delegate bool EnumWindowsDelegate(IntPtr hWnd, int lParam);++ [DllImport("user32.dll", EntryPoint = "EnumWindows", ExactSpelling = false, CharSet = CharSet.Auto, SetLastError = true)]+ public static extern bool EnumWindows(EnumWindowsDelegate enumCallback, IntPtr lParam);++ [DllImport("user32.dll")]+ [return: MarshalAs(UnmanagedType.Bool)]+ public static extern bool IsWindowVisible(IntPtr hWnd);++ [DllImport("user32.dll", EntryPoint = "GetWindowLong")]+ public static extern int GetWindowLong32(IntPtr hWnd, int nIndex);++ [DllImport("user32.dll", EntryPoint = "GetWindowLongPtr")]+ public static extern IntPtr GetWindowLongPtr64(IntPtr hWnd, int nIndex);++ [DllImport("user32.dll")]+ public static extern IntPtr BeginDeferWindowPos(int nNumWindows);++ [DllImport("user32.dll")]+ public static extern IntPtr DeferWindowPos(IntPtr hWinPosInfo, IntPtr hWnd,+ [Optional] IntPtr hWndInsertAfter, int x, int y, int cx, int cy, SWP uFlags);++ [DllImport("user32.dll")]+ [return: MarshalAs(UnmanagedType.Bool)]+ public static extern bool EndDeferWindowPos(IntPtr hWinPosInfo);++ [DllImport("user32.dll")]+ public static extern IntPtr GetForegroundWindow();++ [DllImport("user32.dll")]+ public static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);++ [DllImport("user32.dll")]+ public static extern bool SetFocus(IntPtr hWnd);++ [DllImport("user32.dll")]+ public static extern bool ShowWindow(IntPtr hWnd, int X);++ [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]+ public static extern int GetWindowTextLength(IntPtr hWnd);++ [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]+ public static extern int GetWindowText(IntPtr hWnd, [Out] StringBuilder lpString, int nMaxCount);++ [DllImport("user32.dll", SetLastError=true)]+ public static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);++ [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]+ public static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName,int nMaxCount);++ [DllImport("user32.dll")]+ public static extern bool GetWindowRect(IntPtr hwnd, ref WindowRect rectangle);++ [DllImport("user32.dll")]+ public static extern IntPtr GetWindow(IntPtr hWnd, GW uCmd);++ [DllImport("dwmapi.dll")]+ public static extern int DwmGetWindowAttribute(IntPtr hwnd, DwmWindowAttribute dwAttribute, out bool pvAttribute, int cbAttribute);++ [DllImport("user32.dll")]+ public static extern IntPtr GetShellWindow();+ }+}