Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you position a different window

Status
Not open for further replies.

jmprice

Programmer
Jan 24, 2005
8
US
Situation: I am making a program that will run another application. What I am doing taking screen shots of a certain area then comparing the pixels. What I would like to do is make a botton to position the window at a certain x, y coordinate, that way i capture the right area every time.

Thanks
 
Option Explicit

Private Declare Function FindWindow Lib "user32" _
Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long

Private Declare Function IsWindow Lib "user32" _
(ByVal hwnd As Long) As Long
jmprice,

Open Notepad (it will be your window).
In the application, put two text boxes (X and Y coordinates) and a command button:


Private Declare Function SetWindowPos Lib "user32" _
(ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, _
ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long



Private Function AppStillRunning(ByVal pstrWindowName As String, ByRef iolnghWindow As Long) As Boolean

iolnghWindow = FindWindow(vbNullString, pstrWindowName)
AppStillRunning = IsWindow(iolnghWindow) = 1

End Function

Private Sub MoveApp(ByVal pstrWindowName As String, ByVal pintX As Integer, ByVal pintY As Integer)
Dim lnghWindow As Long

If AppStillRunning(pstrWindowName, lnghWindow) Then
SetWindowPos lnghWindow, 0, pintX, pintY, 0, 0, 1
End If
End Sub

Private Sub Command1_Click()

MoveApp "Untitled - Notepad", CInt(Text1.Text), CInt(Text2.Text)
End Sub

vlad
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top