FormHideAPI.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.InteropServices;
  5. using System.Text;
  6. namespace Azylee.WinformSkin.APIUtils
  7. {
  8. public class FormHideAPI
  9. {
  10. [DllImport("user32.dll")]
  11. private static extern Int32 GetWindowLong(IntPtr hwnd, Int32 index);
  12. [DllImport("user32.dll")]
  13. private static extern Int32 SetWindowLong(IntPtr hwnd, Int32 index, Int32 newValue);
  14. private const int GWL_EXSTYLE = (-20);
  15. private const int WS_EX_APPWINDOW = 0x00040000;
  16. private const int WS_EX_TOOLWINDOW = 0x00000080;
  17. public static bool HideTabAltMenu(IntPtr hwnd)
  18. {
  19. bool result = true;
  20. int exStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
  21. if (exStyle == 0)
  22. {
  23. result = false;
  24. }
  25. else
  26. {
  27. exStyle = exStyle & (~WS_EX_APPWINDOW);
  28. exStyle = exStyle | WS_EX_TOOLWINDOW;
  29. if (0 == SetWindowLong(hwnd, GWL_EXSTYLE, exStyle))
  30. {
  31. result = false;
  32. }
  33. }
  34. return result;
  35. }
  36. }
  37. }