有人可以翻译此代码......
int iHandle = NativeWin32.FindWindow(null, "Security Alert");
NativeWin32.SetForegroundWindow(iHandle);
System.Windows.Forms.SendKeys.Send("Y%");
...进入VB.net?
因为我无法在此“安全警报”窗口(上方屏幕截图)上单击“是”。
答案 0 :(得分:1)
试试这个:
<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