tags:

views:

632

answers:

4

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;
A: 

Set the .ShowInTaskbar property of the form to true.

Phoexo
sorry, I haven't given you all the information. this is not my form
valya
A: 

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

tb
how can I do it?
valya
something like...Object O = new Object();O = Process.GetProcessesByName();((Form)O).ShowInTaskBar = true;
tb
no, It's not working
valya
+1  A: 

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

itowlson
thank you! tried both SetWindowLong(pMainWindow, GWL_EXSTYLE, windowStyle and SetWindowLong(pMainWindow, GWL_EXSTYLE, windowStyle but without any result. while googling i've found "just setting the extended window style itself wasn't enough -- it was only able to work correctly upon initialization of the window", maybe it is a problem
valya
...a solution there was to make app window a parent of the window, which we want to edit. but I have no window in my app, it's a dll!
valya
valya
+1  A: 

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);      
}
ParmesanCodice
OH YEAH! Thank you so much!
valya
Cool no problem. If you are maximizing the window from the system tray AKA notify icon, just bear in mind that when the user minimizes the window they will *expect it* to be removed from the taskbar. As I said in my answer, I couldn't get that bit to work...
ParmesanCodice