On 12 Oct 2006 03:11:54 -0700,
te******@hotmai l.com wrote:
Thanks to all of you guys for your help and efforts. I've given
SendMessage a go, but it still won't do (entirely).
My test.txt contains:
{1221,12}
{50,980}
{70,867}
The idea is to move to each position and perform a click. In my case
the first position should minimize any foremost underlying
application.
Second click hits the Win-XP Start-button.
The third click should click somewhat above the the now unfolded list
above the the Start-button and hit Notepad.
In all three cases the mouse moves to the proper position.
Though, the first click doesn't minimize the underlying application
(that could be any maximized app).
The second click performs well and unfolds the Start-button.
The thirc click doesn't open the Notepad (even at the right position).
Here is my full code:
'--code begin
Imports System.Windows. Forms
Imports System.Threadin g
Imports System.IO
Public Class Form1
Public TextInput As String = ""
Public PosX As Integer, PosY As Integer
Dim thSleep As New Thread(AddressO f ReadFile)
#Region "Get window-name, Declares"
Dim myVal1 As Integer
Dim myVal2 As Integer
Dim intHandle As IntPtr = FindWindow("[Class Name Here]",
vbNullString)
Dim intHandle2 As IntPtr = FindWindow(vbNu llString, "Lommeregne r")
Private Declare Function GetForegroundWi ndow _
Lib "user32" () As IntPtr
Private Declare Function SetForegroundWi ndow _
Lib "user32" (ByVal hWnd As IntPtr) As Boolean
Private Declare Function GetWindowThread ProcessId _
Lib "user32" (ByVal hWnd As IntPtr, _
ByVal lpdwProcessId As IntPtr) As Integer
Private Declare Function AttachThreadInp ut _
Lib "user32" (ByVal idAttach As Integer, _
ByVal idAttachTo As Integer, ByVal fAttach As Boolean _
) As Boolean
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindow A" (ByVal lpClassName As String,
_
ByVal lpWindowName As String) As IntPtr
#End Region
Declare Auto Function WindowFromPoint Lib "user32" (ByVal xPoint
As Integer, ByVal yPoint As Integer) As IntPtr
Declare Function SendMessage Lib "user32" Alias "SendMessag eA" _
(ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal
wParam As Integer, ByVal lParam As Integer) As Integer
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e
As System.EventArg s) Handles Button1.Click
Me.WindowState = FormWindowState .Minimized
ReadFile()
End Sub
Sub ReadFile()
Dim sr As StreamReader = New StreamReader("d :\test.txt")
Dim s As String = ""
Do While sr.Peek() >= 0
s = sr.ReadLine()
Console.WriteLi ne(s)
If s.Substring(0, 1) = "{" Then
s = s.Substring(1, s.Length - 2)
Dim myArray() As String = Split(s, ",", ,
CompareMethod.T ext)
PosX = myArray(0)
PosY = myArray(1)
ClickPosition()
Thread.Sleep(50 0)
Else
'TextInput = s
'WriteText()
'Thread.Sleep(5 00)
End If
Loop
sr.Close()
sr.Dispose()
End Sub
Sub ClickPosition()
Dim wnd As IntPtr
Dim pt As Point
pt.X = PosX
pt.Y = PosY
Windows.Forms.C ursor.Position = pt
Const WM_ACTIVATEAPP = &H1C
Const WM_LBUTTONUP = &H202 '//LButton up
Const WM_LBUTTONDOWN = &H201 '//LButton down
wnd = WindowFromPoint (PosX, PosY)
Call SendMessage(wnd , WM_ACTIVATEAPP, 0, 0)
Call SendMessage(wnd , WM_LBUTTONDOWN, 0, 0)
Call SendMessage(wnd , WM_LBUTTONUP, 0, 0)
End Sub
Sub WriteText()
SendKeys.SendWa it(TextInput)
End Sub
End Class
'--code end
Regards /Snedker