diff --git a/ShareX.HelpersLib/Native/NativeMethods.cs b/ShareX.HelpersLib/Native/NativeMethods.cs index 6666ac21d..a5d179b03 100644 --- a/ShareX.HelpersLib/Native/NativeMethods.cs +++ b/ShareX.HelpersLib/Native/NativeMethods.cs @@ -30,19 +30,19 @@ You should have received a copy of the GNU General Public License namespace ShareX.HelpersLib { + #region Delegates + + public delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam); + + public delegate IntPtr HookProc(int nCode, IntPtr wParam, IntPtr lParam); + + #endregion Delegates + public static partial class NativeMethods { - #region Delegates - - public delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam); - - public delegate IntPtr HookProc(int nCode, IntPtr wParam, IntPtr lParam); - - #endregion Delegates - #region user32.dll - [DllImport("user32")] + [DllImport("user32.dll")] public static extern bool AnimateWindow(IntPtr hwnd, int time, AnimateWindowFlags flags); [DllImport("user32.dll")] @@ -98,6 +98,12 @@ public static partial class NativeMethods [DllImport("user32.dll")] public static extern IntPtr GetActiveWindow(); + [DllImport("user32.dll")] + public static extern uint GetClassLong(IntPtr hWnd, int nIndex); + + [DllImport("user32.dll")] + public static extern IntPtr GetClassLongPtr(IntPtr hWnd, int nIndex); + [DllImport("user32.dll")] public static extern bool GetClientRect(IntPtr hWnd, out RECT lpRect); @@ -117,9 +123,6 @@ public static partial class NativeMethods [DllImport("user32.dll")] public static extern IntPtr GetForegroundWindow(); - [DllImport("gdi32.dll")] - public static extern uint GetPixel(IntPtr hdc, int nXPos, int nYPos); - [DllImport("user32.dll")] public static extern bool GetIconInfo(IntPtr hIcon, out IconInfo piconinfo); @@ -190,7 +193,7 @@ public static partial class NativeMethods [return: MarshalAs(UnmanagedType.Bool)] public static extern bool IsZoomed(IntPtr hWnd); - [DllImport("User32.dll")] + [DllImport("user32.dll")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool PrintWindow(IntPtr hwnd, IntPtr hDC, uint nFlags); @@ -299,12 +302,6 @@ public static partial class NativeMethods [DllImport("kernel32.dll", CharSet = CharSet.Auto)] public static extern ushort GlobalDeleteAtom(ushort nAtom); - [DllImport("user32.dll")] - public static extern uint GetClassLong(IntPtr hWnd, int nIndex); - - [DllImport("user32.dll")] - public static extern IntPtr GetClassLongPtr(IntPtr hWnd, int nIndex); - [DllImport("kernel32.dll")] public static extern IntPtr GetModuleHandle(string lpModuleName); @@ -346,6 +343,9 @@ public static partial class NativeMethods [DllImport("gdi32.dll")] public static extern IntPtr CreateDIBSection(IntPtr hdc, [In] ref BITMAPINFOHEADER pbmi, uint pila, out IntPtr ppvBits, IntPtr hSection, uint dwOffset); + [DllImport("gdi32.dll")] + public static extern uint GetPixel(IntPtr hdc, int nXPos, int nYPos); + #endregion gdi32.dll #region gdiplus.dll @@ -372,7 +372,6 @@ public static partial class NativeMethods [DllImport("shell32.dll")] public static extern IntPtr SHAppBarMessage(uint dwMessage, [In] ref APPBARDATA pData); - // http://stackoverflow.com/questions/14600987/code-to-open-windows-explorer-or-focus-if-exists-with-file-selected [DllImport("shell32.dll")] public static extern int SHOpenFolderAndSelectItems(IntPtr pidlFolder, int cild, IntPtr apidl, int dwFlags); diff --git a/ShareX.HelpersLib/Native/NativeMethods_Helpers.cs b/ShareX.HelpersLib/Native/NativeMethods_Helpers.cs index b276ded6b..22c273d49 100644 --- a/ShareX.HelpersLib/Native/NativeMethods_Helpers.cs +++ b/ShareX.HelpersLib/Native/NativeMethods_Helpers.cs @@ -361,15 +361,6 @@ public static bool IsWindowCloaked(IntPtr handle) return false; } - public static IntPtr SetHook(int hookType, HookProc hookProc) - { - using (Process currentProcess = Process.GetCurrentProcess()) - using (ProcessModule currentModule = currentProcess.MainModule) - { - return SetWindowsHookEx(hookType, hookProc, GetModuleHandle(currentModule.ModuleName), 0); - } - } - public static void RestoreWindow(IntPtr handle) { WINDOWPLACEMENT wp = new WINDOWPLACEMENT(); diff --git a/ShareX.ScreenCaptureLib/RegionHelpers/WindowsList.cs b/ShareX.ScreenCaptureLib/RegionHelpers/WindowsList.cs index 4dfdd8da4..a6b0efd71 100644 --- a/ShareX.ScreenCaptureLib/RegionHelpers/WindowsList.cs +++ b/ShareX.ScreenCaptureLib/RegionHelpers/WindowsList.cs @@ -50,7 +50,7 @@ public WindowsList(IntPtr ignoreWindow) : this() public List GetWindowsList() { windows = new List(); - NativeMethods.EnumWindowsProc ewp = EvalWindows; + EnumWindowsProc ewp = EvalWindows; NativeMethods.EnumWindows(ewp, IntPtr.Zero); return windows; } diff --git a/ShareX.ScreenCaptureLib/RegionHelpers/WindowsRectangleList.cs b/ShareX.ScreenCaptureLib/RegionHelpers/WindowsRectangleList.cs index 8d0e8404a..9c08f8d84 100644 --- a/ShareX.ScreenCaptureLib/RegionHelpers/WindowsRectangleList.cs +++ b/ShareX.ScreenCaptureLib/RegionHelpers/WindowsRectangleList.cs @@ -69,7 +69,7 @@ public List GetWindowInfoList() windows = new List(); parentHandles = new HashSet(); - NativeMethods.EnumWindowsProc ewp = EvalWindow; + EnumWindowsProc ewp = EvalWindow; NativeMethods.EnumWindows(ewp, IntPtr.Zero); List result = new List(); @@ -137,7 +137,7 @@ private bool CheckHandle(IntPtr handle, bool isWindow) { parentHandles.Add(handle); - NativeMethods.EnumWindowsProc ewp = EvalControl; + EnumWindowsProc ewp = EvalControl; NativeMethods.EnumChildWindows(handle, ewp, IntPtr.Zero); }