How to make window appear in taskbar?

隐身守侯 提交于 2019-12-12 09:46:14

问题


A window is not showing in the task bar, only in the system tray. How can I make it show up in the taskbar as well?

I tried the following code, but it had no effect:

int windowStyle = GetWindowLong(pMainWindow, GWL_EXSTYLE);
SetWindowLong(pMainWindow, GWL_EXSTYLE, windowStyle & WS_EX_TOOLWINDOW);

And, this is NOT my form! I'm getting the handle from Process.GetProcessesByName and I don't know how to access properties of the Form class:

Process[] processes = Process.GetProcessesByName("somename");
someProcess = processes[0];

pMainWindow = someProcess.MainWindowHandle;

回答1:


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);      
}



回答2:


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...




回答3:


Set the .ShowInTaskbar property of the form to true.




回答4:


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



来源:https://stackoverflow.com/questions/1462504/how-to-make-window-appear-in-taskbar

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