1

I need to open an external window from an external exe (eg Notepad) and move & size it to a predefined size & position.

I am trying to use MoveWindow API but is seems it is not working. I am using Windows 8 x64 and VS2012.

Here is my code:

    <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
4

1 回答 1

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
于 2013-10-30T16:07:06.320 回答