NativeMethods.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using System.Security;
  4. namespace PicView.Native
  5. {
  6. //https://msdn.microsoft.com/en-us/library/ms182161.aspx
  7. [SuppressUnmanagedCodeSecurity]
  8. internal static class NativeMethods
  9. {
  10. [DllImport("shlwapi.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
  11. internal static extern int StrCmpLogicalW(string x, string y);
  12. [DllImport("User32.dll")]
  13. internal static extern bool SetCursorPos(int x, int y);
  14. // Used to check for wallpaper support
  15. [DllImport("user32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
  16. [return: MarshalAs(UnmanagedType.Bool)]
  17. internal static extern bool SystemParametersInfo(uint uiAction, uint uiParam,
  18. string pvParam, uint fWinIni);
  19. // file properties
  20. //http://stackoverflow.com/a/1936957
  21. private const int SW_SHOW = 5;
  22. private const uint SEE_MASK_INVOKEIDLIST = 12;
  23. [DllImport("shell32.dll", CharSet = CharSet.Auto)]
  24. private static extern bool ShellExecuteEx(ref SHELLEXECUTEINFO lpExecInfo);
  25. internal static bool ShowFileProperties(string Filename)
  26. {
  27. var info = new SHELLEXECUTEINFO();
  28. info.cbSize = Marshal.SizeOf(info);
  29. info.lpVerb = "properties";
  30. info.lpParameters = "details";
  31. info.lpFile = Filename;
  32. info.nShow = SW_SHOW;
  33. info.fMask = SEE_MASK_INVOKEIDLIST;
  34. return ShellExecuteEx(ref info);
  35. }
  36. [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
  37. internal struct SHELLEXECUTEINFO
  38. {
  39. public int cbSize;
  40. public uint fMask;
  41. public IntPtr hwnd;
  42. [MarshalAs(UnmanagedType.LPTStr)]
  43. public string lpVerb;
  44. [MarshalAs(UnmanagedType.LPTStr)]
  45. public string lpFile;
  46. [MarshalAs(UnmanagedType.LPTStr)]
  47. public string lpParameters;
  48. [MarshalAs(UnmanagedType.LPTStr)]
  49. public readonly string lpDirectory;
  50. public int nShow;
  51. public IntPtr hInstApp;
  52. public IntPtr lpIDList;
  53. [MarshalAs(UnmanagedType.LPTStr)]
  54. public readonly string lpClass;
  55. public IntPtr hkeyClass;
  56. public readonly uint dwHotKey;
  57. public IntPtr hIcon;
  58. public IntPtr hProcess;
  59. }
  60. [DllImport("shell32.dll", CharSet = CharSet.Auto, SetLastError = true)]
  61. public static extern void SHChangeNotify(uint wEventId, uint uFlags, IntPtr dwItem1, IntPtr dwItem2);
  62. /// <summary>
  63. /// Used to disable Screensaver and Power options.
  64. /// </summary>
  65. internal const uint ES_CONTINUOUS = 0x80000000;
  66. internal const uint ES_SYSTEM_REQUIRED = 0x00000001;
  67. internal const uint ES_DISPLAY_REQUIRED = 0x00000002;
  68. [DllImport("kernel32.dll", SetLastError = true)]
  69. public static extern uint SetThreadExecutionState([In] uint esFlags);
  70. }
  71. }