試試這個:
<System.Runtime.InteropServices.DllImport("user32.dll")> _
Private Shared Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As String) As System.IntPtr
End Function
<Runtime.InteropServices.DllImport("user32.dll", SetLastError:=True, CharSet:=Runtime.InteropServices.CharSet.Auto)> _
Private Shared Function SetForegroundWindow(ByVal hWnd As IntPtr) As Long
End Function
Public Sub HandleWindows()
Dim iPtr As Integer = FindWindow(Nothing, "MyWindow")
SetForegroundWindow(iPtr)
SendKeys.SendWait("{ENTER}")
End Sub
或者,你可以把窗口的句柄與進程,是這樣的:
Public Function GetWindowHandle() As Integer
Dim proc As Process = Process.GetProcessesByName("OUTLOOK")(0)
If proc IsNot Nothing AndAlso proc.MainWindowTitle.Equals("Security Alert") Then
return proc.MainWindowHandle()
End If
return 0
End Sub
我不相信你正在嘗試去就是好實踐。該盒子在那裏通知用戶安全證書存在問題。這是他們的選擇,不是你的潮溼或不繼續。 –
......這就是說,pinvoke.net擁有所有WinAPI調用的所有功能,比如'FindWindow'。 'SetForegroundWindow'似乎是它們的別名'SetActiveWindow' – Plutonix
只是提到...如果用戶安裝了另一種語言,那麼發送字母'Y'可能什麼都不做。 – SysDragon