如标题。PS Tray Factory这个工具可以实现将windows任务栏的图标隐藏并在托盘区创建一个小图标,这样的功能使用C#如何实现?

解决方案 »

  1.   

    额两位,能不能具体的告诉下,调用哪个winapi啊
      

  2.   

    this.ShowInTaskbar = false;  
    private void Form1_SizeChanged(object sender, EventArgs e)
    {
    if(this.WindowState==FormWindowState.Minimized)
    {
    this.Hide();
    this.notifyIcon1.Visible=true;
    }
    }
    private void notifyIcon1_Click(object sender, EventArgs e)
    {
    this.Visible = true;
    this.WindowState = FormWindowState.Normal;
    this.notifyIcon1.Visible = false;
      

  3.   

    http://topic.csdn.net/t/20020902/20/990675.html
    这个应该是你想要的吧
      

  4.   

    五楼只能实现程序自身显示在任务栏的上,不能因此任务栏上的图标。
    你要的效果没有做过,就是Tray Factory的效果,这里给出一个让你通过点击按钮,隐藏掉整个任务栏的效果://定义API:
    [DllImport("User32.dll", EntryPoint="FindWindow", CharSet=CharSet.Auto)]
    public static extern  int FindWindow(String className, String captionName);

    [DllImport("User32.dll", EntryPoint="ShowWindow", CharSet=CharSet.Auto)]
    public static extern int ShowWindow(int hwnd,int nCmdShow); private void sBtn_HideBar_Click(object sender, System.EventArgs e)
    {
    //Hide the Task Pane
    ShowWindow(FindWindow("Shell_TrayWnd",null),0);
    } private void sBtn_ShowBar_Click(object sender, System.EventArgs e)
    {
    //Show Task Pane
    ShowWindow(FindWindow("Shell_TrayWnd",null),5);
    }
      

  5.   

    隐藏任务栏就是
    [DllImport("user32.dll", EntryPoint = "FindWindowEx", SetLastError = true)]
    static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
    [DllImport("user32.dll", EntryPoint = "ShowWindow", SetLastError = true)]
    static extern bool ShowWindow(IntPtr hWnd, uint nCmdShow);
    显示/隐藏任务栏窗口 
    //IntPtr trayHwnd = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "Shell_TrayWnd", null);
    IntPtr trayHwnd = FindWindow("Shell_TrayWnd", null);
    if (trayHwnd != IntPtr.Zero)  
     {  
      ShowWindow(trayHwnd, 0);
    }
     ShowWindow 的第二参数, 1 表示显示, 0 表示隐藏
      

  6.   

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;
    using System.Runtime.InteropServices;
    using System.Diagnostics;
    using System.IO;
    namespace WindowsFormsApplication1
    {    public partial class frmmain : Form
        {
             
            public frmmain()
            {
                InitializeComponent();
                textBox1.Text = DateTime.Now.ToString();
          
            }
            string skkw = null;
            public frmmain(string skk)
            {
                InitializeComponent();
                textBox1.Text = DateTime.Now.ToString();
                skkw = skk;
            }
            string date=null;
            public void frmmain_Load(object sender, EventArgs e)
            {
                Loadx();
                date = DateTime.Today.ToShortDateString();
               // this.Visible = false;
                MenuItem menuItem1 = new MenuItem("显示窗口");            MenuItem menuWeb = new MenuItem("显示首页");            MenuItem menuItem2 = new MenuItem("隐藏窗口");            MenuItem menuItem3 = new MenuItem("执行程序");            MenuItem menuItem4 = new MenuItem("退出程序");            //分别为4个菜单项添加Click事件响应函数            menuItem1.Click += new System.EventHandler(this.menuItem1_Click);            menuItem1.MeasureItem += new System.Windows.Forms.MeasureItemEventHandler(this.menuItem1_MeasureItem);            menuItem1.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.menuItem1_ItemDraw);            menuItem2.Click += new System.EventHandler(this.menuItem2_Click);            menuItem3.Click += new System.EventHandler(this.menuItem3_Click);            menuItem4.Click += new System.EventHandler(this.menuItem4_Click);            menuWeb.Click += new EventHandler(this.menuWeb_Click);            //设置NotifyIcon对象的ContextMenu属性为生面的弹出菜单对象            notifyIcon1.ContextMenu = new ContextMenu(new MenuItem[] { menuItem1, menuItem2, menuWeb, menuItem3, menuItem4 });            //当用户双击程序图标时将执行相应的函数            notifyIcon1.Text = DateTime.Now.ToString("yyyy-MM-dd");
           
            }        private void menuItem1_Click(object sender, System.EventArgs e)//“显示窗口”菜单的响应方法
            {            if (this.Visible == false)
                {
                    this.Visible = true;//假如当前窗口没显示则显示当前窗口
                    this.WindowState = FormWindowState.Normal;
                }        }        private void menuItem2_Click(object sender, System.EventArgs e)//"隐藏窗口"菜单的响应方法
            {            if (this.Visible == true)
                {
                    this.Visible = false;//假如当前窗口为显示的则隐藏窗口
                    this.WindowState = FormWindowState.Normal;
                }        }        private void menuItem3_Click(object sender, System.EventArgs e)//"执行程序"菜单的响应方法
            {            //显示一个提示信息框,表示事件已经得到响应
                MessageBox.Show("演示程序已经执行,此处功能就是显示一个提示框!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);        }        private void menuItem4_Click(object sender, System.EventArgs e)//“退出程序”菜单的响应方法
            {            this.Close();//关闭当前对象(即窗体)            Application.Exit();//通过Application类的静态方法Exit()退出应用程序        }
            /// <summary>
            /// 切换到web页面
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void menuWeb_Click(object sender, System.EventArgs e)
            {
                System.Diagnostics.Process.Start("IEXPLORE.EXE", "http://hi.csdn.net/space.php?do=home");
            }
            private void menuItem1_ItemDraw(object sender, System.Windows.Forms.DrawItemEventArgs e)
            {
                Image newImage = Image.FromFile("sss.ico");
                Point ulCorner = new Point(100, 100);
                Point urCorner = new Point(550, 100);
                Point llCorner = new Point(150, 250);
                Point[] destPara = { ulCorner, urCorner, llCorner };
                e.Graphics.DrawImage(newImage, destPara);
            }
            private void menuItem1_MeasureItem(object sender, System.Windows.Forms.MeasureItemEventArgs e)
            {
                e.ItemHeight = 100;
                e.ItemWidth = 100;
            }
    // notifyIcon1显示托盘的组件
            private void notifyIcon1_DoubleClick(object sender, EventArgs e)
            {
                this.Visible = true;   
                this.WindowState = FormWindowState.Normal;
            }
    / /窗口缩小事件到托盘
            private void frmmain_SizeChanged(object sender, EventArgs e)
            {
                if (this.WindowState == FormWindowState.Minimized)
                {
                    this.Visible = false;
                    //this.notifyIcon1.Visible = true;
                }
            }
            private void frmmain_FormClosed(object sender, FormClosedEventArgs e)
            {
                Application.Exit();
            }
        }
    }
      

  7.   

    正好我也想搞个类似功能(隐藏任务栏上的某程序图标),这是从网上找到的例子,还在研究中。http://www.csframework.com/archive/2/arc-2-20110712-1687.htm
      

  8.   

    1. Added to namespace definitions
     
    using System.Runtime.InteropServices;
     
    2. Declared P/Invoke in my Form1 class
     
    [DllImport("user32.dll")]
     public static extern int SetWindowLong( IntPtr window, int index, int
     value);
     
    [DllImport("user32.dll")]
     public static extern int GetWindowLong( IntPtr window, int index);
     
    const int GWL_EXSTYLE = -20;
     const int WS_EX_TOOLWINDOW = 0x00000080;
     const int WS_EX_APPWINDOW = 0x00040000;
     
    3. I copied this code in the Form1_Load method
     
    this.WindowState = System.Windows.Forms.FormWindowState.Minimized;
     this.Visible = false;
     this.ShowInTaskbar = false;
     int windowStyle = GetWindowLong(Handle, GWL_EXSTYLE);
     SetWindowLong(Handle, GWL_EXSTYLE, windowStyle | WS_EX_TOOLWINDOW);
     
      

  9.   

    好了,我也可以回下你的结果了:
    以下是代码:using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;namespace joke
    {
        public partial class Form1 : Form
        {
            [DllImport("user32.dll")]
            private static extern int FindWindow(String className, String WindowText);
            [DllImport("user32.dll")]
            private static extern int ShowWindow(int hwnd, int command);
            private const int Sw_Hide = 0;
            private const int Sw_Show = 1;
            protected static int Handle
            {
                get
                {
                    return FindWindow("Sword3 Class", "剑侠情缘·网络版");
                }
            }        public Form1()
            {
                InitializeComponent();
            }               private void toolStripButton1_Click(object sender, EventArgs e)
            {
                ShowWindow(Handle, Sw_Hide);
            }        private void toolStripButton2_Click(object sender, EventArgs e)
            {
                ShowWindow(Handle, Sw_Show);
            }
        }
    }
      

  10.   

    主要是Findwindow你需要隐藏的程序出来就可以了。如果不知道程序的Classname和名称可以用C#中的spy++来查看你的程序属性。