i want to move a program that already is running, and by move, i mean change the x and y coordinates of the application on the screen. how would i go about doing this?
Printable View
i want to move a program that already is running, and by move, i mean change the x and y coordinates of the application on the screen. how would i go about doing this?
here's an example that finds + moves an instance of notepad:
vb Code:
Public Class Form1 Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr Const HWND_TOPMOST As Integer = -1 Const HWND_NOTOPMOST As Integer = -2 Const SWP_NOSIZE As Integer = &H1 Const SWP_NOACTIVATE As Integer = &H10 Const SWP_SHOWWINDOW As Integer = &H40 Private Declare Sub SetWindowPos Lib "User32" (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) Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim iHwnd As IntPtr = FindWindow("notepad", vbNullString) SetWindowPos(iHwnd, HWND_TOPMOST, 100, 100, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOSIZE) End Sub End Class
this works nicely, but how would i go about finding the window from process id, instead of a name?
try GetProcessById,
Code:Dim p = Process.GetProcessById(pid)
Dim iHwnd = p.MainWindowHandle
If Not iHwnd.Equals(IntPtr.Zero) Then
SetWindowPos(iHwnd, .....
thanks very much :) i tried to use process.getprocessbyid, but i did it wrong :D