question

Labi-6582 avatar image
0 Votes"
Labi-6582 asked ·

SendMessage to Watermarking Edit Controls

Hello Guys,

I would like to write in an other application Watermarking (for example: Type here) search textbox .
75051-empty.jpg

I tried usung the sendMassage methods, but it was unsuccesful. If the textbox is unfocused I changed only the grayed watermarked text.
74918-empty2.jpg

If I clicked in the textbox with mouse after works well.
75004-empty3.jpg

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






dotnet-visual-basic
empty.jpg (10.1 KiB)
empty2.jpg (9.9 KiB)
empty3.jpg (10.1 KiB)
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Castorix31 avatar image
0 Votes"
Castorix31 answered ·

Another test (works for standard Edit controls, not sure for your control...) =>

        PostMessage(hWndDest, WM_LBUTTONDOWN, 0, IntPtr.Zero)
        PostMessage(hWndDest, WM_LBUTTONUP, 0, IntPtr.Zero)
        PostMessage(hWndDest, WM_CHAR, Keys.A, IntPtr.Zero)

Declarations :

 <DllImport("User32.dll", SetLastError:=True, CharSet:=CharSet.Auto)>
 Public Shared Function PostMessage(ByVal hWnd As IntPtr, ByVal msg As UInteger, ByVal wParam As Integer, ByVal lParam As IntPtr) As Integer
 End Function

 Public Const WM_CHAR = &H102
 Public Const WM_LBUTTONDOWN = &H201
 Public Const WM_LBUTTONUP = &H202
·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Castorix31 avatar image
0 Votes"
Castorix31 answered ·

WM_SETTEXT works for me :

75017-cuebanner.gif



 Dim hWndDest As IntPtr = IntPtr.Zero
 hWndDest = &H511E8 ' Test on an Edit control handle with Cue Banner
 SendMessage(hWndDest, WM_SETTEXT, 0, Marshal.StringToHGlobalUni("This is a test"))

Declarations :

 <DllImport("User32.dll", SetLastError:=True, CharSet:=CharSet.Unicode)>
 Public Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As IntPtr) As Integer
 End Function
    
 Public Const WM_SETTEXT = &HC



cuebanner.gif (45.2 KiB)
·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Labi-6582 avatar image
0 Votes"
Labi-6582 answered ·

Thanks.
Not working :(

I noticed that the textbox handle changes when a search is performed when I press an enter.
When I click the box again, the handle is different. That is, the Watermark text handle is different and the normal typed text handle is different.
Can I get somehow a normal text handle? I also only see WinSpy ++ when I click and type in it.

· 1 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Is it a standard "Edit" control ?
In my test, I tested with a C# TextBox ("WindowsForms10.EDIT.app.xxx..." class = standard Win32 "Edit" control class) in which I sent EM_SETCUEBANNER

0 Votes 0 ·
Labi-6582 avatar image
0 Votes"
Labi-6582 answered ·

I think not.
This is SAP Bussines One cliend search box

·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Labi-6582 avatar image
0 Votes"
Labi-6582 answered ·

THANKS!!
:)
WORKING

· 1 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Mark as "right answer" the answer with the code which works (with PostMessage), because it is difficult to find atm...

0 Votes 0 ·