mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-01 09:47:22 +13:00
Few NativeMethods changes
This commit is contained in:
parent
c5687ce3dd
commit
06c29e2d33
4 changed files with 22 additions and 32 deletions
|
@ -30,19 +30,19 @@ You should have received a copy of the GNU General Public License
|
||||||
|
|
||||||
namespace ShareX.HelpersLib
|
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
|
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
|
#region user32.dll
|
||||||
|
|
||||||
[DllImport("user32")]
|
[DllImport("user32.dll")]
|
||||||
public static extern bool AnimateWindow(IntPtr hwnd, int time, AnimateWindowFlags flags);
|
public static extern bool AnimateWindow(IntPtr hwnd, int time, AnimateWindowFlags flags);
|
||||||
|
|
||||||
[DllImport("user32.dll")]
|
[DllImport("user32.dll")]
|
||||||
|
@ -98,6 +98,12 @@ public static partial class NativeMethods
|
||||||
[DllImport("user32.dll")]
|
[DllImport("user32.dll")]
|
||||||
public static extern IntPtr GetActiveWindow();
|
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")]
|
[DllImport("user32.dll")]
|
||||||
public static extern bool GetClientRect(IntPtr hWnd, out RECT lpRect);
|
public static extern bool GetClientRect(IntPtr hWnd, out RECT lpRect);
|
||||||
|
|
||||||
|
@ -117,9 +123,6 @@ public static partial class NativeMethods
|
||||||
[DllImport("user32.dll")]
|
[DllImport("user32.dll")]
|
||||||
public static extern IntPtr GetForegroundWindow();
|
public static extern IntPtr GetForegroundWindow();
|
||||||
|
|
||||||
[DllImport("gdi32.dll")]
|
|
||||||
public static extern uint GetPixel(IntPtr hdc, int nXPos, int nYPos);
|
|
||||||
|
|
||||||
[DllImport("user32.dll")]
|
[DllImport("user32.dll")]
|
||||||
public static extern bool GetIconInfo(IntPtr hIcon, out IconInfo piconinfo);
|
public static extern bool GetIconInfo(IntPtr hIcon, out IconInfo piconinfo);
|
||||||
|
|
||||||
|
@ -190,7 +193,7 @@ public static partial class NativeMethods
|
||||||
[return: MarshalAs(UnmanagedType.Bool)]
|
[return: MarshalAs(UnmanagedType.Bool)]
|
||||||
public static extern bool IsZoomed(IntPtr hWnd);
|
public static extern bool IsZoomed(IntPtr hWnd);
|
||||||
|
|
||||||
[DllImport("User32.dll")]
|
[DllImport("user32.dll")]
|
||||||
[return: MarshalAs(UnmanagedType.Bool)]
|
[return: MarshalAs(UnmanagedType.Bool)]
|
||||||
public static extern bool PrintWindow(IntPtr hwnd, IntPtr hDC, uint nFlags);
|
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)]
|
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
|
||||||
public static extern ushort GlobalDeleteAtom(ushort nAtom);
|
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")]
|
[DllImport("kernel32.dll")]
|
||||||
public static extern IntPtr GetModuleHandle(string lpModuleName);
|
public static extern IntPtr GetModuleHandle(string lpModuleName);
|
||||||
|
|
||||||
|
@ -346,6 +343,9 @@ public static partial class NativeMethods
|
||||||
[DllImport("gdi32.dll")]
|
[DllImport("gdi32.dll")]
|
||||||
public static extern IntPtr CreateDIBSection(IntPtr hdc, [In] ref BITMAPINFOHEADER pbmi, uint pila, out IntPtr ppvBits, IntPtr hSection, uint dwOffset);
|
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
|
#endregion gdi32.dll
|
||||||
|
|
||||||
#region gdiplus.dll
|
#region gdiplus.dll
|
||||||
|
@ -372,7 +372,6 @@ public static partial class NativeMethods
|
||||||
[DllImport("shell32.dll")]
|
[DllImport("shell32.dll")]
|
||||||
public static extern IntPtr SHAppBarMessage(uint dwMessage, [In] ref APPBARDATA pData);
|
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")]
|
[DllImport("shell32.dll")]
|
||||||
public static extern int SHOpenFolderAndSelectItems(IntPtr pidlFolder, int cild, IntPtr apidl, int dwFlags);
|
public static extern int SHOpenFolderAndSelectItems(IntPtr pidlFolder, int cild, IntPtr apidl, int dwFlags);
|
||||||
|
|
||||||
|
|
|
@ -361,15 +361,6 @@ public static bool IsWindowCloaked(IntPtr handle)
|
||||||
return false;
|
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)
|
public static void RestoreWindow(IntPtr handle)
|
||||||
{
|
{
|
||||||
WINDOWPLACEMENT wp = new WINDOWPLACEMENT();
|
WINDOWPLACEMENT wp = new WINDOWPLACEMENT();
|
||||||
|
|
|
@ -50,7 +50,7 @@ public WindowsList(IntPtr ignoreWindow) : this()
|
||||||
public List<WindowInfo> GetWindowsList()
|
public List<WindowInfo> GetWindowsList()
|
||||||
{
|
{
|
||||||
windows = new List<WindowInfo>();
|
windows = new List<WindowInfo>();
|
||||||
NativeMethods.EnumWindowsProc ewp = EvalWindows;
|
EnumWindowsProc ewp = EvalWindows;
|
||||||
NativeMethods.EnumWindows(ewp, IntPtr.Zero);
|
NativeMethods.EnumWindows(ewp, IntPtr.Zero);
|
||||||
return windows;
|
return windows;
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,7 @@ public List<SimpleWindowInfo> GetWindowInfoList()
|
||||||
windows = new List<SimpleWindowInfo>();
|
windows = new List<SimpleWindowInfo>();
|
||||||
parentHandles = new HashSet<IntPtr>();
|
parentHandles = new HashSet<IntPtr>();
|
||||||
|
|
||||||
NativeMethods.EnumWindowsProc ewp = EvalWindow;
|
EnumWindowsProc ewp = EvalWindow;
|
||||||
NativeMethods.EnumWindows(ewp, IntPtr.Zero);
|
NativeMethods.EnumWindows(ewp, IntPtr.Zero);
|
||||||
|
|
||||||
List<SimpleWindowInfo> result = new List<SimpleWindowInfo>();
|
List<SimpleWindowInfo> result = new List<SimpleWindowInfo>();
|
||||||
|
@ -137,7 +137,7 @@ private bool CheckHandle(IntPtr handle, bool isWindow)
|
||||||
{
|
{
|
||||||
parentHandles.Add(handle);
|
parentHandles.Add(handle);
|
||||||
|
|
||||||
NativeMethods.EnumWindowsProc ewp = EvalControl;
|
EnumWindowsProc ewp = EvalControl;
|
||||||
NativeMethods.EnumChildWindows(handle, ewp, IntPtr.Zero);
|
NativeMethods.EnumChildWindows(handle, ewp, IntPtr.Zero);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue