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;
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?
来源:https://stackoverflow.com/questions/1462504/how-to-make-window-appear-in-taskbar