Hiding window from taskbar in C# with WinAPI

。_饼干妹妹 提交于 2019-12-07 07:11:39

问题


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!


回答1:


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)




回答2:


Set Form's ShowInTaskbar property to false.



来源:https://stackoverflow.com/questions/3260757/hiding-window-from-taskbar-in-c-sharp-with-winapi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!