I'm trying to position a couple of external windows from within my application but either end up with just a piece of the title bar on screen near the top left or the window goes far to the right and ends up at x = 32767
The function declarations are in a module and the Move_Notepad Sub is part of a form.
Option Explicit On
Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function MoveWindow Lib "user32.dll" Alias "MoveWindow" (ByVal hwnd As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long
Public Sub Move_Notepad()
'Move NotePad to 1,1 and set its Width and height to 800,720 (pixels)
Dim GoWindow As Long
hWinHand = FindWindow(vbNullString, "Untitled - Notepad")
GoWindow = MoveWindow(hWinHand, 1, 1, 800, 720, 1)
End Sub
Private Sub bMove_Notepad_Click(sender As Object, e As EventArgs) Handles bMove_Notepad.Click
Move_Notepad()
End Sub
I installed the PInvoke.net Visual Studio Extension extension and got the following code which finallyworked for me: