Dim hwnd As IntPtr = FindWindow(Nothing, "代码窗口")
If hwnd <> IntPtr.Zero Then
msgbox("找到窗口")
Dim btn = FindWindowEx(hwnd, 0, "WindowsForms10.BUTTON.app.0.378734a", "退出")
If btn <> IntPtr.Zero Then
msgbox("找到按钮")
'SendMessage(btn, &Hf5, 0, 0)
End If
End If
全局代码
<DllImport("user32.dll", EntryPoint := "FindWindow", SetLastError := True)> _
Public Function FindWindow(lpClassName As String, lpWindowName As String) As IntPtr
End Function
<DllImport("user32.dll", EntryPoint := "FindWindowEx", SetLastError := True)> _
Public Function FindWindowEx(hwndParent As IntPtr, hwndChildAfter As UInteger, lpszClass As String, lpszWindow As String) As IntPtr
End Function
<DllImport("user32.dll", EntryPoint := "SendMessage", SetLastError := True, CharSet := CharSet.Auto)> _
Public Function SendMessage(hwnd As IntPtr, wMsg As UInteger, wParam As IntPtr, lParam As String) As Integer
End Function