我需要从外部exe(例如记事本)打开外部窗口并移动&将其大小调整为预定义的大小&位置。
我正在尝试使用MoveWindow API,但似乎它无效。我使用的是Windows 8 x64和VS2012。
这是我的代码:
<DllImport("user32.dll")> _
Public Function MoveWindow(ByVal hWnd As IntPtr, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal bRepaint As Boolean) As Boolean
End Function
Public Sub NoveNotepad()
Dim ApplicationProcess = System.Diagnostics.Process.Start("Notepad.exe")
ApplicationProcess.WaitForInputIdle()
Dim ApplicationHandle = ApplicationProcess.MainWindowHandle
Dim z = MoveWindow(ApplicationHandle, 600, 600, 600, 600, True) ' THIS RETURNS TRUE
End Sub
答案 0 :(得分:0)
您可以尝试使用SetWindowPos()吗?不确定为什么MoveWindow()不起作用......
Private Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos" _
(ByVal hwnd As IntPtr, ByVal hWndInsertAfter As Integer, _
ByVal x As Integer, ByVal y As Integer, ByVal cx As Integer, ByVal cy As Integer, _
ByVal wFlags As Integer) As Integer
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim ApplicationProcess = System.Diagnostics.Process.Start("Notepad.exe")
ApplicationProcess.WaitForInputIdle()
Dim ApplicationHandle = ApplicationProcess.MainWindowHandle
SetWindowPos(ApplicationHandle, 0, 600, 600, 600, 600, 0)
End Sub