Visual Studio 開發人員中心 > Visual Studio 論壇 > Visual Basic > 利用 FindWindow API 找到特定標題視窗,卻無法將其帶到前景?
發問發問
 

已答覆利用 FindWindow API 找到特定標題視窗,卻無法將其帶到前景?

  • 2007年3月15日 下午 05:40Tommy1231 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     

    我用 FindWindow API 找到特定標題視窗

    卻無法將其帶到前景,程式碼如下,是哪裡弄錯了嗎?

    請前輩指點一下,謝謝喔!

    (經查 ShowWindow 回傳 0
    SetForegroundWindow 回傳非0)

             Dim handle As IntPtr = FindWindow(vbNullString, "未命名 - 記事本")
             If Not IntPtr.Zero.Equals(handle) Then
                    'MsgBox(handle.ToInt32)
                    Dim r As Integer
                    r = ShowWindow(handle, SW_RESTORE)
                    'MsgBox(r)
                    r = SetForegroundWindow(handle)
                    'MsgBox(r)
              End If

     

    API宣告如下

    Const SW_RESTORE=9

    <System.Runtime.InteropServices.DllImport("user32.dll", _
        EntryPoint:="SetForegroundWindow", _
        CallingConvention:=Runtime.InteropServices.CallingConvention.StdCall, _
        CharSet:=Runtime.InteropServices.CharSet.Unicode, SetLastError:=True)> _
        Public Shared Function SetForegroundWindow(ByVal handle As IntPtr) As Integer

        End Function

        <System.Runtime.InteropServices.DllImport("user32.dll", _
        EntryPoint:="ShowWindow", _
        CallingConvention:=Runtime.InteropServices.CallingConvention.StdCall, _
        CharSet:=Runtime.InteropServices.CharSet.Unicode, SetLastError:=True)> _
        Public Shared Function ShowWindow(ByVal handle As IntPtr, ByVal mode As APIWindowMode) As Integer

        End Function

     

解答

所有回覆