Win32.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Runtime.InteropServices;
  7. namespace SmartCoalApplication.SystemLayer.FileDlgExtenders.Win32Types
  8. {
  9. internal static class NativeMethods
  10. {
  11. #region Delegates
  12. internal delegate bool EnumWindowsCallBack(IntPtr hWnd, int lParam);
  13. #endregion
  14. #region USER32
  15. [DllImport("user32.dll")]
  16. public static extern bool IsWindow(IntPtr hwnd);
  17. [DllImport("user32.dll")]
  18. internal static extern IntPtr CreateWindowEx(
  19. uint dwExStyle, string lpClassName, string lpWindowName, uint dwStyle, int x, int y,
  20. int nWidth, int nHeight, IntPtr hWndParent, IntPtr hMenu, IntPtr hInstance, IntPtr lpParam);
  21. [DllImport("user32.dll", CharSet = CharSet.Auto)]
  22. public static extern IntPtr GetParent(IntPtr hWnd);
  23. [DllImport("user32.dll")]
  24. internal static extern bool EnableWindow(IntPtr hWnd, bool bEnable);
  25. [DllImport("user32.dll")]
  26. internal static extern IntPtr GetDlgItem(IntPtr hDlg, int nIDDlgItem);
  27. [DllImport("user32.dll")]
  28. internal static extern bool SetDlgItemText(IntPtr hDlg, int nIDDlgItem, string lpString);
  29. [DllImport("User32.Dll")]
  30. public static extern int GetDlgCtrlID(IntPtr hWndCtl);
  31. [DllImport("user32.dll", SetLastError = true)]
  32. [return: MarshalAs(UnmanagedType.Bool)]
  33. internal static extern bool GetWindowInfo(HandleRef hwnd, out WINDOWINFO pwi);
  34. [DllImport("user32.dll")]
  35. [return: MarshalAs(UnmanagedType.Bool)]
  36. public static extern bool SetWindowText(HandleRef hWnd, string lpString);
  37. [DllImport("User32.Dll")]
  38. public static extern void GetClassName(HandleRef hWnd, StringBuilder param, int length);
  39. [DllImport("user32.Dll")]
  40. [return: MarshalAs(UnmanagedType.Bool)]
  41. public static extern bool EnumChildWindows(HandleRef hWndParent, EnumWindowsCallBack lpEnumFunc, int lParam);
  42. [DllImport("user32.dll", SetLastError = true)]
  43. public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className, string windowTitle);
  44. [DllImport("user32.dll", SetLastError = true)]
  45. public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className, IntPtr windowTitle);
  46. [DllImport("user32.dll")]
  47. internal static extern IntPtr SetParent(HandleRef hWndChild, HandleRef hWndNewParent);
  48. [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
  49. internal static extern IntPtr SendMessage(HandleRef hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
  50. [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
  51. internal static extern IntPtr SendMessage(HandleRef hWnd, uint Msg, IntPtr wParam, StringBuilder lParam);
  52. [DllImport("user32.dll", CharSet = CharSet.Auto)]
  53. public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int Width, int Height, SetWindowPosFlags flags);
  54. [DllImport("user32.dll")]
  55. [return: MarshalAs(UnmanagedType.Bool)]
  56. internal static extern bool GetWindowRect(HandleRef hwnd, ref RECT rect);
  57. [DllImport("user32.dll")]
  58. [return: MarshalAs(UnmanagedType.Bool)]
  59. internal static extern bool GetClientRect(HandleRef hwnd, ref RECT rect);
  60. [DllImport("user32.dll")]
  61. [return: MarshalAs(UnmanagedType.Bool)]
  62. public static extern bool DestroyWindow(IntPtr hWnd);
  63. [DllImport("advapi32.dll", EntryPoint = "RegCreateKeyW")]
  64. public static extern int RegCreateKeyW([In] UIntPtr hKey, [In] [MarshalAs(UnmanagedType.LPWStr)] string lpSubKey, out IntPtr phkResult);
  65. [DllImport("advapi32.dll", EntryPoint = "RegOverridePredefKey")]
  66. public static extern int RegOverridePredefKey([In] UIntPtr hKey, [In] IntPtr hNewHKey);
  67. [DllImport("advapi32.dll", EntryPoint = "RegCloseKey")]
  68. public static extern int RegCloseKey([In] IntPtr hKey);
  69. /*
  70. [DllImport("user32.dll")]
  71. public static extern IntPtr SetActiveWindow(IntPtr hWnd);
  72. [DllImport("user32.dll")]
  73. public static extern IntPtr SetForegeoundWindow(IntPtr hWnd);
  74. */
  75. #endregion
  76. }
  77. }