How to make a program not show up in Alt-Tab or on the taskbar

≯℡__Kan透↙ 提交于 2019-12-05 00:50:17
Chris Taylor

You can create a hidden window that you use to handle the messages.

using System;
using System.Windows.Forms;

namespace WindowsApplication1
{
  class Program
  {
    [STAThread]
    static void Main(string[] args)
    {
      Application.Run(new MessageWindow());        
    }
  }

  class MessageWindow : Form
  {
    public MessageWindow()
    {
      this.ShowInTaskbar = false;
      this.WindowState = FormWindowState.Minimized;
      // added by MusiGenesis 5/7/10:
      this.FormBorderStyle = FormBorderStyle.FixedToolWindow;
    }

    protected override void WndProc(ref Message m)
    {
      base.WndProc(ref m);
    }
  }
}  
MusiGenesis

See this question: Best way to hide a window from the Alt-Tab program switcher?

I tried all of the solutions, but no matter what I do the window still shows up in the Alt-Tab list (I'm running Vista).

In Windows Mobile, you set a form's Text property to blank to keep it out of the running programs list (the WinMo equivalent of the alt-tab list). Perhaps this will work for you, but I doubt it.

Update: OK, this does work after all. If you create and show a form with its FormBorderStyle set to FixedToolWindow and its ShowInTaskbar set to false it will not appear in the Alt-Tab list.

Paste this, into your code:

protected override CreateParams CreateParams
        {
            get
            {
                CreateParams pm = base.CreateParams;
                pm.ExStyle |= 0x80;
                return pm;
            }
        }

Simple as that. Works perfectly on win7 64bit and whats more important - it doesnt require, to change form border style (i've created a widget-like application so setting style to fixedToolWindow was not an option, with this solution its still borderless and invisible for alt-tab).

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