How to make window appear in taskbar?

无人久伴 提交于 2019-12-06 02:47:35

The following seems to do the trick. If you hide & reshow the window after calling SetWindowLong it then shows in the taskbar.

I'm struggling to find a way to remove it from the taskbar once the window is minimized...

[DllImport("User32.Dll")]                
public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);

[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

private const int SW_HIDE = 0x00;
private const int SW_SHOW = 0x05;

private const int WS_EX_APPWINDOW = 0x40000;
private const int GWL_EXSTYLE = -0x14;

private void ShowWindowInTaskbar(IntPtr pMainWindow)
{                       
    SetWindowLong(pMainWindow, GWL_EXSTYLE, WS_EX_APPWINDOW);

    ShowWindow(pMainWindow, SW_HIDE);
    ShowWindow(pMainWindow, SW_SHOW);      
}

Pass WS_EX_APPWINDOW instead of WS_EX_TOOLWINDOW. From the docs:

WS_EX_APPWINDOW: Forces a top-level window onto the taskbar when the window is visible.

WS_EX_TOOLWINDOW: ...A tool window does not appear in the taskbar or in the dialog that appears when the user presses ALT+TAB...

Set the .ShowInTaskbar property of the form to true.

Can you cast the object returned Process.GetProcessesByName() as a form, then set its .ShowInTaskbar property?

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