You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 line
1.8 KiB

  1. // This code is distributed under MIT license.
  2. // Copyright (c) 2015 George Mamaladze
  3. // See license.txt or https://mit-license.org/
  4. using System;
  5. using System.Runtime.InteropServices;
  6. namespace Gma.System.MouseKeyHook.WinApi
  7. {
  8. internal static class ThreadNativeMethods
  9. {
  10. /// <summary>
  11. /// Retrieves the unmanaged thread identifier of the calling thread.
  12. /// </summary>
  13. /// <returns></returns>
  14. [DllImport("kernel32")]
  15. internal static extern int GetCurrentThreadId();
  16. /// <summary>
  17. /// Retrieves a handle to the foreground window (the window with which the user is currently working).
  18. /// The system assigns a slightly higher priority to the thread that creates the foreground window than it does to
  19. /// other threads.
  20. /// </summary>
  21. /// <returns></returns>
  22. [DllImport("user32.dll", CharSet = CharSet.Auto)]
  23. internal static extern IntPtr GetForegroundWindow();
  24. /// <summary>
  25. /// Retrieves the identifier of the thread that created the specified window and, optionally, the identifier of the
  26. /// process that
  27. /// created the window.
  28. /// </summary>
  29. /// <param name="handle">A handle to the window. </param>
  30. /// <param name="processId">
  31. /// A pointer to a variable that receives the process identifier. If this parameter is not NULL,
  32. /// GetWindowThreadProcessId copies the identifier of the process to the variable; otherwise, it does not.
  33. /// </param>
  34. /// <returns>The return value is the identifier of the thread that created the window. </returns>
  35. [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
  36. internal static extern int GetWindowThreadProcessId(IntPtr handle, out int processId);
  37. }
  38. }