如何使程序不使用Alt-Tab或任务栏上显示 [英] How to make a program not show up in Alt-Tab or on the taskbar

查看:218
本文介绍了如何使程序不使用Alt-Tab或任务栏上显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在后台坐着,当用户连接到一个RDP会话它会做一些环境设置,然后启动一个程序的程序。当程序关闭时它会做一些家务和注销会话。



我做它目前的方式是我的终端服务器启动该应用程序。这是建立一个Windows窗体应用程序,以保持控制台窗口的显示出来:

 公共静态无效的主要()
{
//(略...)做一些设置工作

过程PROC =新工艺();
//(略...)安装的过程
proc.Start();
proc.WaitForExit();

//(略...)做一些大扫除

NativeMethods.ExitWindowsEx(0,0);
}



我真的很喜欢这一点,因为有任务栏没有项目,没有什么显示了在使用Alt-Tab。然而,要做到这一点,我放弃了访问功能,如 无效的WndProc(参考消息M) 所以现在我不能听窗口消息(如 WTS_REMOTE_DISCONNECT WTS_SESSION_LOGOFF ),并没有一个手柄要用于的 布尔WTSRegisterSessionNotification(IntPtr的的HWND,诠释的dwFlags); 我想我的代码更健壮如此如果用户注销或他闭上程序之前从会话断开它会做大扫除。



这是我怎么能有我的鱼和熊掌兼得呢?


解决方案

您可以创建用于处理消息的隐藏的窗口。

 使用系统;使用System.Windows.Forms的
;

命名空间的WindowsApplication1
{
类节目
{
[STAThread]
静态无效的主要(字串[] args)
{
Application.Run(新消息窗());
}
}

类消息窗:表
{
公共消息窗()
{
this.ShowInTaskbar = FALSE;
this.WindowState = FormWindowState.Minimized;
//通过MusiGenesis 10年5月7日表示:
this.FormBorderStyle = FormBorderStyle.FixedToolWindow;
}

保护覆盖无效的WndProc(参考消息M)
{
base.WndProc(REF米);
}
}
}


I have a program that needs to sit in the background and when a user connects to a RDP session it will do some environment setup then launch a program. When the program is closed it will do some housekeeping and logoff the session.

The current way I am doing it is I have the terminal server launch this application. This is built as a windows forms application to keep the console window from showing up:

public static void Main()
{
    //(Snip...) Do some setup work

    Process proc = new Process();
    //(Snip...) Setup the process
    proc.Start();
    proc.WaitForExit();

    //(Snip...) Do some housecleaning

    NativeMethods.ExitWindowsEx(0, 0);
}

I really like this because there is no item in the taskbar and there is nothing showing up in alt-tab. However to do this I gave up access to functions like void WndProc(ref Message m) So Now I can't listen to windows messages (Like WTS_REMOTE_DISCONNECT or WTS_SESSION_LOGOFF) and do not have a handle to use for for bool WTSRegisterSessionNotification(IntPtr hWnd, int dwFlags); I would like my code to be more robust so it will do the housecleaning if the user logs off or disconnects from the session before he closes the program.

Any reccomendations on how I can have my cake and eat it too?

解决方案

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

这篇关于如何使程序不使用Alt-Tab或任务栏上显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆