Private Sub PT_Command(ByVal strCMD As String)
Try
Dim ret As Integer
Dim Rec1 As Rectangle = New Rectangle
Find Window
Dim returnValue() As Diagnostics.Process
returnValue = Process.GetProcessesByName(prgWindow)
Dim hwnd As IntPtr = returnValue(0).MainWindowHandle
strWinClass = get_ClassName(hwnd)
Dim PTools_hWnd As IntPtr = FindWindowExA(hwnd, 0, strWinClass, vbNullString) finds child windows
Get Left, Right, Top and Bottom of Form1
Dim success As Boolean = GetWindowRect(hwnd, Rec1)
Debug.WriteLine(String.Format("Rec1={0}", Rec1))
If Not success Then
Throw New Win32Exception
End If
GetWindowRect returning zero values
Tried both hwnd & PTools_hWnd
If UCase(strCMD) = "PLAY" Then
MoveCursor((Rec1.Left + x1), (Rec1.Top + y1))
ElseIf UCase(strCMD) = "STOP" Then
MoveCursor((Rec1.Left + x2), (Rec1.Top + y2))
End If
If Not SetForegroundWindow(hwnd) Then
Throw New Win32Exception
End If
If newPoint.Equals(Cursor.Position) Then
mouse_event(2, 0, 0, 0, IntPtr.Zero)
mouse_event(4, 0, 0, 0, IntPtr.Zero)
Else
SendKeys.Send(" ")
End If
Catch ex As Exception
Dim tempData() As String
Dim I As Integer
SendKeys.Send(" ")
tempData = Split(ex.ToString, vbCrLf)
For I = LBound(tempData) To UBound(tempData)
TextBox1.AppendText(Now & vbTab & tempData(I) & vbCrLf)
Next
End Try
End Sub
Private Sub MoveCursor(ByVal Fx As Integer, ByVal Fy As Integer)
newPoint = New Point(Fx, Fy)
Debug.WriteLine(String.Format("Old mouse position = {0}.", Cursor.Position))
Debug.WriteLine(String.Format("Moving mouse to {0}.", newPoint))
Cursor.Position = newPoint
End Sub
Public Function get_ClassName(ByVal intHandle As IntPtr) As String
Dim builder1 As New StringBuilder(256)
Dim num1 As Integer = GetClassName(intHandle, builder1, 256)
Return builder1.ToString(0, num1)
End Function