1 using System; 2 using System.Runtime.InteropServices; 3 4 namespace x 5 { 6 unsafe class NativeWindow 7 { 8 /* 9 * Window field offsets for GetWindowLong() 10 */ 11 public const int GWL_WNDPROC = (-4); 12 public const int GWL_HINSTANCE = (-6); 13 public const int GWL_HWNDPARENT = (-8); 14 public const int GWL_STYLE = (-16); 15 public const int GWL_EXSTYLE = (-20); 16 public const int GWL_USERDATA = (-21); 17 public const int GWL_ID = (-12); 18 19 public const int GWLP_WNDPROC = (-4); 20 public const int GWLP_HINSTANCE = (-6); 21 public const int GWLP_HWNDPARENT = (-8); 22 public const int GWLP_USERDATA = (-21); 23 public const int GWLP_ID = (-12); 24 25 26 27 /* 28 * ShowWindow() Commands 29 */ 30 public const int SW_HIDE = 0; 31 public const int SW_SHOWNORMAL = 1; 32 public const int SW_NORMAL = 1; 33 public const int SW_SHOWMINIMIZED = 2; 34 public const int SW_SHOWMAXIMIZED = 3; 35 public const int SW_MAXIMIZE = 3; 36 public const int SW_SHOWNOACTIVATE = 4; 37 public const int SW_SHOW = 5; 38 public const int SW_MINIMIZE = 6; 39 public const int SW_SHOWMINNOACTIVE = 7; 40 public const int SW_SHOWNA = 8; 41 public const int SW_RESTORE = 9; 42 public const int SW_SHOWDEFAULT = 10; 43 public const int SW_FORCEMINIMIZE = 11; 44 public const int SW_MAX = 11; 45 46 47 [DllImport("user32.dll")] 48 public static extern IntPtr GetTaskmanWindow(); 49 50 [DllImport("user32.dll")] 51 public static extern IntPtr SendMessageA( 52 [In] IntPtr hWnd, 53 [In] int Msg, 54 [In] IntPtr wParam, 55 [In] IntPtr lParam 56 ); 57 58 [DllImport("user32.dll")] 59 public static extern int SetWindowLongA( 60 [In] IntPtr hWnd, 61 [In] int nIndex, 62 [In] int dwNewLong 63 ); 64 65 [DllImport("user32.dll")] 66 public static extern IntPtr SetWindowLongPtrA( 67 [In] IntPtr hWnd, 68 [In] int nIndex, 69 [In] IntPtr dwNewLong 70 ); 71 72 [DllImport("user32.dll")] 73 public static extern bool ShowWindow( 74 [In] IntPtr hWnd, 75 [In] int nCmdShow 76 ); 77 78 private IntPtr _hWnd; 79 private bool _bShowInTaskbar; 80 81 public bool ShowInTaskbar 82 { 83 get { return _bShowInTaskbar; } 84 85 set 86 { 87 if (value) 88 { 89 SetWindowLongCore(_hWnd, GWLP_HWNDPARENT, GetTaskmanWindow()); 90 } 91 else 92 { 93 SetWindowLongCore(_hWnd, GWLP_HWNDPARENT, (IntPtr)0); 94 } 95 SendMessageA(hwndroot, WM_SETREDRAW, (IntPtr)0, (IntPtr)0); 96 ShowWindow(hwndroot, SW_HIDE); 97 ShowWindow(hwndroot, SW_SHOW); 98 SendMessageA(hwndroot, WM_SETREDRAW, (IntPtr)1, (IntPtr)0); 99 _bShowInTaskbar = value; 100 } 101 } 102 103 public NativeWindow() { } 104 105 public static IntPtr SetWindowLongCore(IntPtr hWnd, int nIndex, IntPtr dwNewLong) 106 { 107 if (sizeof(void*) == 4) 108 { 109 return (IntPtr)SetWindowLongA(hWnd, nIndex, (int)dwNewLong); 110 } 111 return SetWindowLongPtrA(hWnd, nIndex, dwNewLong); 112 } 113 114 } 115 }
C# WinForm ShowInTaskbar Api Version
猜你喜欢
转载自www.cnblogs.com/shitekudasai/p/7239035.html
今日推荐
周排行