我想做一个小程序,让它最小化后仍然能监视系统当前窗口的标题,如果发现指定的窗口标题,它给予相应的提示!
请问各位高手,我这个想法能实现吗?
有意 请附上部分源码,感谢!

解决方案 »

  1.   

    在winform中用notifyIcon做成托盘图标的还是?要不然,窗体最小化后就是不活动的了,你只能去遍历,听听楼下高手的解答
      

  2.   

    新建一个WinForm工程,然后把Program.cs的内容请空换成下面代码。程序将运行在系统托盘区。
    using System;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;static class Program
    {
        [STAThread]
        static void Main()
        {
            ContextMenu menu = new ContextMenu(new MenuItem[]{
                new MenuItem("Exit", delegate(object sender, EventArgs e){ Application.Exit();})
            });        notifyIcon1.ContextMenu = menu;
            notifyIcon1.Icon = System.Drawing.SystemIcons.Question;
            notifyIcon1.Text = "My application showing the active window...";
            notifyIcon1.Visible = true;        Timer timer = new Timer();
            timer.Interval = 200;
            timer.Tick += OnTimerTick;
            timer.Start();        Application.Run();
            timer.Dispose();
        }    static void OnTimerTick(object sender, EventArgs e )
        {
            char[] buf = new char[64];
            IntPtr hWnd = GetForegroundWindow();
            if (hWnd != IntPtr.Zero)
            {
                int length = GetWindowTextW(hWnd, buf, buf.Length);
                if (length > 0)
                {
                    notifyIcon1.Text = new string(buf, 0, length);
                }
            }
        }    static NotifyIcon notifyIcon1 = new NotifyIcon();
        
        [DllImport("User32.dll", CharSet=CharSet.Unicode)]
        extern static int GetWindowTextW(IntPtr hWnd, char[] str, int nMaxCount);    [DllImport("User32.dll")]
        extern static IntPtr GetForegroundWindow();
    }
      

  3.   

    不太清楚你要的效果,请问是否是像spy++那样东西