Few NativeMethods changes

This commit is contained in:
Jaex 2016-11-21 08:37:42 +03:00
parent c5687ce3dd
commit 06c29e2d33
4 changed files with 22 additions and 32 deletions

View file

@ -30,19 +30,19 @@
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);

View file

@ -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();

View file

@ -50,7 +50,7 @@ public WindowsList(IntPtr ignoreWindow) : this()
public List<WindowInfo> GetWindowsList()
{
windows = new List<WindowInfo>();
NativeMethods.EnumWindowsProc ewp = EvalWindows;
EnumWindowsProc ewp = EvalWindows;
NativeMethods.EnumWindows(ewp, IntPtr.Zero);
return windows;
}

View file

@ -69,7 +69,7 @@ public List<SimpleWindowInfo> GetWindowInfoList()
windows = new List<SimpleWindowInfo>();
parentHandles = new HashSet<IntPtr>();
NativeMethods.EnumWindowsProc ewp = EvalWindow;
EnumWindowsProc ewp = EvalWindow;
NativeMethods.EnumWindows(ewp, IntPtr.Zero);
List<SimpleWindowInfo> result = new List<SimpleWindowInfo>();
@ -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);
}