locked
Hide icon in ALT+TAB RRS feed

  • Question

  •  

    Simple question: how do I hide a window icon in the ALT-TAB WPF-window?

    Tuesday, September 25, 2007 8:44 PM

Answers

  • Here is simple answer for simple question Wink

     

    I've found cool way how to make invisible the window icon in Alt-Tab panel. This approach does not require Interop and WinForms stuff (as you may see in different solutions). The only drawback is that additional window is created... but probably this solutioin

     

    Write few lines of codein the constructor of you main window:

     

    Code Snippet

    public partial class WindowMain : Window

    {

    public WindowMain()

    {

    //--------------------------------------------------

    // put your initialization logic here...

    //--------------------------------------------------

     

    Window w = new Window(); // Create helper window

    w.Top = -100; // Location of new window is outside of visible part of screen

    w.Left = -100;

    w.Width = 1; // size of window is enough small to avoid its appearance at the beginning

    w.Height = 1;

    w.WindowStyle = WindowStyle.ToolWindow; // Set window style as ToolWindow to avoid its icon in AltTab 

    w.Show(); // We need to show window before set is as owner to our main window

    this.Owner = w; // Okey, this will result to disappear icon for main window.

    w.Hide(); // Hide helper window just in case

    }

    }

     

     

    Modifications of this trick may include using transparent borderless helper window.

     

    Anybody, please criticise this approach. In which cases this trick may be bad solution?

     

    Any comments are very appreciated!

     

    PS. You may also use modification of this approach to resolve another problem (Icon + ShowInTaskBar=false):

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=933642&SiteID=1

     

     

     

     

    • Proposed as answer by chaiguy1337 Wednesday, December 17, 2008 10:43 PM
    • Marked as answer by Tao Liang Wednesday, March 11, 2009 7:15 AM
    Wednesday, March 5, 2008 7:25 PM

All replies

  • I think when window has WS_EX_TOOLWINDOW style it is not in Alt-Tab list. (WS_EX_TOOLWINDOW = 0x00000080)

     

    Also if window is not main window (when it has Owner property set) it is not in that list.

     

    If you want to set that style for WPF main window you can use something like HwndSource.

     

    You can check this http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=491476&SiteID=1

    Friday, September 28, 2007 12:07 AM
  •  

    My problems are that (1) I need a borderless window and (2) I can't set the Owner property because I'm opening this window from a WindowForms application. And the Owner needs to be a System.Windows.Window object.
    Saturday, September 29, 2007 2:24 PM
  • Example in thread that I linked in previous post creates LayeredWindow that is not in Alt-Tab list. It means borderless window that can have transparent areas and is not in Alt-Tab list.

     

    Specifying ExtendedWindowStyle to WS_EX_TOOLWINDOW is not same as setting

    Window.WindowStyle to ToolWindow (enumeration).

     

    So if I understood you correctly, you are creating window and you don't want to have its icon in Alt-Tab list and to achieve that setting WS_EX_TOOLWINDOW to ExtendedWindowStyle should make it.

     

     

     

    Last time when I did .Net 2.0 Forms project I also needed borderless Window that is not in Alt-Tab (was like some kind of watermark) and I used Layered Window - I implemented class derrived from Form with:

     

    protected override CreateParams CreateParams

    {

    get

    {

    CreateParams cp = base.CreateParams;

    cp.ExStyle |= 0x00000080; // WS_EX_TOOLWINDOW (hide from Alt + Tab)

    cp.ExStyle |= 0x00080000; // WS_EX_LAYERED (create layered window)

    cp.ExStyle |= 0x00000020; // WS_EX_TRANSPARENT - mouse events go through

    //cp.ExStyle |= 0x08000000; // WS_EX_NOACTIVATE

    return cp;

    }

    }

     

    Sunday, September 30, 2007 12:43 AM
  • Could you use the Popup class? I would like to understand your scenario better. Maybe solution is for wpf to improve Popup so it can be used in your scenario.

     

    In terms of workaround, I think the direct hwnd interop one should work fine. You should also be set the Owner to a WinForms hwnd through WindowInteropHelper:

     

    WindowInteropHelper wih = new WindowInteropHelper(window);

    wih.Owner = form.Handle;

     

     

    Wednesday, October 3, 2007 1:55 AM
  • Here is simple answer for simple question Wink

     

    I've found cool way how to make invisible the window icon in Alt-Tab panel. This approach does not require Interop and WinForms stuff (as you may see in different solutions). The only drawback is that additional window is created... but probably this solutioin

     

    Write few lines of codein the constructor of you main window:

     

    Code Snippet

    public partial class WindowMain : Window

    {

    public WindowMain()

    {

    //--------------------------------------------------

    // put your initialization logic here...

    //--------------------------------------------------

     

    Window w = new Window(); // Create helper window

    w.Top = -100; // Location of new window is outside of visible part of screen

    w.Left = -100;

    w.Width = 1; // size of window is enough small to avoid its appearance at the beginning

    w.Height = 1;

    w.WindowStyle = WindowStyle.ToolWindow; // Set window style as ToolWindow to avoid its icon in AltTab 

    w.Show(); // We need to show window before set is as owner to our main window

    this.Owner = w; // Okey, this will result to disappear icon for main window.

    w.Hide(); // Hide helper window just in case

    }

    }

     

     

    Modifications of this trick may include using transparent borderless helper window.

     

    Anybody, please criticise this approach. In which cases this trick may be bad solution?

     

    Any comments are very appreciated!

     

    PS. You may also use modification of this approach to resolve another problem (Icon + ShowInTaskBar=false):

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=933642&SiteID=1

     

     

     

     

    • Proposed as answer by chaiguy1337 Wednesday, December 17, 2008 10:43 PM
    • Marked as answer by Tao Liang Wednesday, March 11, 2009 7:15 AM
    Wednesday, March 5, 2008 7:25 PM
  • Thanks Ivan! That's the only solution I've come across so far that works, and works reliably!
    Wednesday, December 17, 2008 10:43 PM