Results 1 to 5 of 5

Thread: [RESOLVED] position external application?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    1,023

    Resolved [RESOLVED] position external application?

    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?

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: position external application?

    here's an example that finds + moves an instance of notepad:

    vb Code:
    1. Public Class Form1
    2.  
    3.     Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
    4.  
    5.     Const HWND_TOPMOST As Integer = -1
    6.     Const HWND_NOTOPMOST As Integer = -2
    7.     Const SWP_NOSIZE As Integer = &H1
    8.     Const SWP_NOACTIVATE As Integer = &H10
    9.     Const SWP_SHOWWINDOW As Integer = &H40
    10.  
    11.     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)
    12.  
    13.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    14.         Dim iHwnd As IntPtr = FindWindow("notepad", vbNullString)
    15.         SetWindowPos(iHwnd, HWND_TOPMOST, 100, 100, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOSIZE)
    16.     End Sub
    17.  
    18. End Class

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    1,023

    Re: position external application?

    this works nicely, but how would i go about finding the window from process id, instead of a name?

  4. #4
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: position external application?

    Quote Originally Posted by Justa Lol View Post
    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, .....

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    1,023

    Re: position external application?

    thanks very much i tried to use process.getprocessbyid, but i did it wrong

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width