Win32.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*******************************************************************************
  2. * Copyright(c) 2012 dongke All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:Win32.cs
  5. * 2.功能描述:系统中Win32的控制类
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 欧阳涛 2012/06/07 1.00 新建
  9. *******************************************************************************/
  10. using System;
  11. using System.Runtime.InteropServices;
  12. namespace Dongke.IBOSS.PRD.Basics.Library
  13. {
  14. /// <summary>
  15. /// 系统中Win32的控制类
  16. /// </summary>
  17. public static class Win32
  18. {
  19. #region User32
  20. public const int SW_RESTORE = 9;
  21. public const int SC_CLOSE = 0xF060;
  22. public const int MF_ENABLED = 0x00000000;
  23. public const int MF_GRAYED = 0x00000001;
  24. public const int MF_DISABLED = 0x00000002;
  25. public const int WM_SYSCOMMAND = 0x112;
  26. public const int WM_QUERYENDSESSION = 0x11;
  27. public const int WM_CUSTOM_FW = 0x1024;
  28. [DllImport("gdi32.dll")]
  29. private static extern int GetDeviceCaps(IntPtr hdc, int Index);
  30. [DllImport("user32.dll", CharSet = CharSet.Auto)]
  31. public static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, int lParam);
  32. [DllImport("user32.dll", CharSet = CharSet.Auto)]
  33. public static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, int lParam);
  34. [DllImport("user32.dll")]
  35. public static extern bool SetForegroundWindow(IntPtr hWnd);
  36. [DllImport("user32.dll")]
  37. public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
  38. [DllImport("user32.dll")]
  39. public static extern bool IsIconic(IntPtr hWnd);
  40. [DllImport("user32.dll")]
  41. public static extern bool IsWindowEnabled(IntPtr hWnd);
  42. [DllImport("user32.dll")]
  43. public static extern bool IsWindowVisible(IntPtr hWnd);
  44. [DllImport("user32.dll")]
  45. public static extern bool EnableWindow(IntPtr hwnd, bool bEnable);
  46. [DllImport("user32.dll")]
  47. public static extern bool PrintWindow(IntPtr hwnd, IntPtr hdcBlt, uint nFlags);
  48. [DllImport("user32.dll", EntryPoint = "GetSystemMenu")]
  49. public static extern IntPtr GetSystemMenu(IntPtr hWnd, int bRevert);
  50. [DllImport("User32.dll")]
  51. public static extern bool EnableMenuItem(IntPtr hMenu, int uIDEnableItem, int uEnable);
  52. #endregion
  53. #region Shell32
  54. public const uint SHGFI_ICON = 0x100;
  55. public const uint SHGFI_LARGEICON = 0x0;
  56. public const uint SHGFI_SMALLICON = 0x1;
  57. public struct SHFILEINFO
  58. {
  59. public IntPtr hIcon;
  60. public IntPtr iIcon;
  61. public uint dwAttributes;
  62. [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
  63. public string szDisplayName;
  64. [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]
  65. public string szTypeName;
  66. };
  67. [DllImport("shell32.dll")]
  68. public static extern IntPtr SHGetFileInfo(string pszPath, uint dwFileAttributes,
  69. ref SHFILEINFO psfi, uint cbSizeFileInfo, uint uFlags);
  70. #endregion
  71. #region Kernel32
  72. public static readonly IntPtr InvalidHandleValue = new IntPtr(-1);
  73. public const uint FILE_MAP_WRITE = 0x02;
  74. public const uint FILE_MAP_READ = 0x04;
  75. public const uint PAGE_READWRITE = 0x04;
  76. [DllImport("Kernel32")]
  77. public static extern IntPtr CreateFileMapping(IntPtr hFile,
  78. IntPtr pAttributes, uint flProtect,
  79. uint dwMaximumSizeHigh, uint dwMaximumSizeLow, string pName);
  80. [DllImport("Kernel32")]
  81. public static extern IntPtr OpenFileMapping(uint dwDesiredAccess,
  82. bool bInheritHandle, string name);
  83. [DllImport("Kernel32")]
  84. public static extern bool CloseHandle(IntPtr handle);
  85. [DllImport("Kernel32")]
  86. public static extern IntPtr MapViewOfFile(IntPtr hFileMappingObject,
  87. uint dwDesiredAccess,
  88. uint dwFileOffsetHigh, uint dwFileOffsetLow,
  89. IntPtr dwNumberOfBytesToMap);
  90. [DllImport("Kernel32")]
  91. public static extern bool UnmapViewOfFile(IntPtr address);
  92. [DllImport("Kernel32")]
  93. public static extern bool DuplicateHandle(IntPtr hSourceProcessHandle,
  94. IntPtr hSourceHandle,
  95. IntPtr hTargetProcessHandle, ref IntPtr lpTargetHandle,
  96. uint dwDesiredAccess, bool bInheritHandle, uint dwOptions);
  97. public const uint DUPLICATE_CLOSE_SOURCE = 0x00000001;
  98. public const uint DUPLICATE_SAME_ACCESS = 0x00000002;
  99. [DllImport("Kernel32")]
  100. public static extern IntPtr GetCurrentProcess();
  101. #endregion
  102. }
  103. }