Hello Guys,
I would like to write in an other application Watermarking (for example: Type here) search textbox .
I tried usung the sendMassage methods, but it was unsuccesful. If the textbox is unfocused I changed only the grayed watermarked text.
If I clicked in the textbox with mouse after works well.
I tried to make mouse events on this textbox, but not the best solution because sometimes some form over on this textbox. I tried to activate the control, but not worked. I tested the SendKey method too.
Could you help me?
Thanks,
Istvan
Here is the code:
Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As String) As Integer
Private Declare Function SendKey Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As IntPtr, wMsg As Int32, wParam As Byte, lParam As Int32) As Int32
Private Const WM_SETTEXT As Integer = &HC
Private Const WM_ACTIVATE As Integer = &H6
Private Const WA_ACTIVE As Integer = &H1
Const WM_CHAR = &H102
Const WM_KEYDOWN As Integer = &H100
Const WM_KEYUP As Integer = &H101
Sub SendTextToTextbox()
Dim iHwndChild3 As IntPtr = FindWindowEx(iHwndChild2a, IntPtr.Zero, "TMEditTextClass", vbNullString)
SendMessage(iHwndChild3, WM_ACTIVATE, 0, 0) SendMessage(iHwndChild3, WM_SETTEXT, IntPtr.Zero, "Text to send")
'Alternatively use SendKey methods
' SendKeysO(iHwndChild3, 25, "Text to send" & vbLf)
End Sub
Public Sub SendKeysO(handle As IntPtr, delay As Integer, chars As String)
Dim Bytes As List(Of Byte) = System.Text.Encoding.ASCII.GetBytes(chars).ToList
For Each B As Byte In Bytes
If B = 10 Then
SendKey(handle, WM_KEYDOWN, CByte(Keys.Enter), 0)
SendKey(handle, WM_KEYUP, CByte(Keys.Enter), 1)
End If
SendKey(handle, WM_CHAR, B, 0)
Dim Sw As Stopwatch = Stopwatch.StartNew
Do
Application.DoEvents()
Loop Until Sw.ElapsedMilliseconds >= delay
Next
End Sub