[DllImport("user32")]     
  public   static   extern   unsafe   int   FindWindow(string   sClassName,string   WindowName);     
  [DllImport("user32")]     
  public   static   extern   unsafe   bool   SetForegroundWindow(int   hWnd);   
    
  private   bool   AppActivate(string   sWindowName)   
  {   
  int   hwind   =   FindWindow(null,sWindowName);   
  if   (hwind   ==   0)   
  return   false;   
  SetForegroundWindow(hwind);   
  return   true;   
  }   
    
  if   (AppActivate("notepad"))     
  {   
  System.Windows.Forms.SendKeys.SendWait("%(f)o");   
  ....   
  }   
    
  将notepad最小化,可以发送。
代码片段如上,本人从没有使用过C#,所以对上面很简单的代码理解不了,希望有人帮忙写出完成的代码.连接如下http://www.21cnvip.com/csdn/default.aspx?q=20031222/21/2591646.html.谢谢啊

解决方案 »

  1.   

    namespace ConsoleApplication1
    {
       
        class Program
        {
            [DllImport("user32.dll")]
            public static extern unsafe int FindWindow(string sClassName, string WindowName);
            [DllImport("user32.dll")]
            public static extern unsafe bool SetForegroundWindow(int hWnd);        private static bool AppActivate(string sWindowName)
            {
                int hwind = FindWindow(sWindowName, null);
                if (hwind == 0)
                    return false;
                SetForegroundWindow(hwind);
                return true;
            }          static void Main(string[] args)
            {
                if (AppActivate("Notepad"))     
                  {   
                     System.Windows.Forms.SendKeys.SendWait("%(f)U");   
                  }           }
        }
    }呵呵分给自己了.