简体   繁体   中英

Hiding window from taskbar in C# with WinAPI

Believe me, I have Googled it and expected it to be a fairly easy find - turns out it isn't. I have my window handle, but no form. How do I do it? Thanks!

Declare these:

 [DllImport("user32.dll", SetLastError = true)]
static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll")]
static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
private const int GWL_EX_STYLE = -20;
private const int WS_EX_APPWINDOW = 0x00040000, WS_EX_TOOLWINDOW = 0x00000080;

And then use this before the form is shown:


SetWindowLong(handle, GWL_EX_STYLE, (GetWindowLong(handle, GWL_EX_STYLE) | WS_EX_TOOLWINDOW) & ~WS_EX_APPWINDOW);

(change handle to whatever your window handle is stored in)

将Form的ShowInTaskbar属性设置为false。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM