try:[DllImport("user32.dll")]
private static extern int SetForegroundWindow (int hwnd);SetForegroundWindow(ParenthWnd);

解决方案 »

  1.   

    [DllImport("user32.dll")]
    public static extern IntPtr SetFocus(IntPtr hwnd);
    ...
    SetFocus(hwnd);
      

  2.   

    [DllImport("user32.dll")]
    private static extern int SetForegroundWindow (int hwnd);SetForegroundWindow(ParenthWnd);
    ==========================
    这是我想要的答案。给分。
    谢谢  BearRui(我有点笨,但我很特别,所以我特别笨!)
      

  3.   

    帖子结的还是挺快的,好同志!!!
    虽然你的问题用SetForegroundWindow能打开窗口,但是如果你的窗口是最小化的话就不行.要想完善一下还要加两个API才行,我写了一个如下的代码你可以参考一下:
    const int SWP_SHOWWINDOW = 0x40;
    const int SWP_NOOWNERZORDER = 0x200;
    const int SWP_NOSENDCHANGING = 0x0400;
    const int SWP_NOSIZE = 0x0001;
    const int SWP_NOMOVE = 0x0002;
    const int HWND_TOP =0;[System.Runtime.InteropServices.DllImport("user32.dll")]
    private static extern IntPtr FindWindow(string strclassName, string strWindowName);[System.Runtime.InteropServices.DllImport("user32.dll")]
    private static extern bool SetWindowPos(IntPtr hWnd, IntPtr pWndInsertAfter,int x,int y,int cx,int cy,uint nFlags );[System.Runtime.InteropServices.DllImport("user32.dll")]
    private static extern bool SetWindowText(IntPtr hWnd, string lpString );[System.Runtime.InteropServices.DllImport("user32.dll")]
    private static extern bool OpenIcon(IntPtr hWnd);[System.Runtime.InteropServices.DllImport("user32.dll")]
    private static extern bool IsIconic(IntPtr hWnd);[System.Runtime.InteropServices.DllImport("user32.dll")]
    private static extern int SetForegroundWindow(IntPtr hWnd);private void OpenForm_Click(object sender, System.EventArgs e)
    {
    string FormTitle = this.textBox1.Text;
    IntPtr hWnd = FindWindow(null, FormTitle);
    if (hWnd != IntPtr.Zero)
    {
    //SetForegroundWindow(o);
    //return;
    bool isIcon = IsIconic(hWnd);
    bool isSuccess = false;
    if ( !isIcon )
    {
    isSuccess = SetWindowPos( hWnd, (IntPtr)HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
    }
    else
    {
    isSuccess = OpenIcon(hWnd);
    }
    //if (isSuccess)
    //SetWindowText( o, "新的标题");
    }
    }