INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Sendmessage / WM_SENDTEXT

Sendmessage / WM_SENDTEXT

(OP)
I'm trying to control a logon screen in another app from my program. It almost works but the WM_SENDTEXT only sends the 1st character of the strings "userid" and "password" I want to send

Dim lRet As Long
    Dim strText As String
    Dim l_LoginWindow As Long
    
    l_LoginWindow = FindWindow("WindowsForms10.Window.8.app.0.378734a", vbNullString)

    lng_LOGON_SCREEN = l_LoginWindow
    Debug.Print "Main Screen Handle"; lng_LOGON_SCREEN
    retval = EnumChildWindows(lng_LOGON_SCREEN, AddressOf EnumChildProc, ByVal 0&)
    strText = "userid"
    Call SendMessage(lng_hLogonUserIdBox, WM_SETTEXT, 0, Asc(strText))
    
    strText = "password"
    Call SendMessage(lng_hLogonPasswordBox, WM_SETTEXT, 0, Asc(strText))

 

RE: Sendmessage / WM_SENDTEXT

(OP)
Got the answer had to use SendMessageString in place of SendMessage

"There is no pleasure in having nothing to do; the fun is having lots to do and not doing it.
." - Andrew Jackson
 

RE: Sendmessage / WM_SENDTEXT

Not really

RE: Sendmessage / WM_SENDTEXT

(OP)
please elaborate am I doing something wrong here. It seems to work

RE: Sendmessage / WM_SENDTEXT

There is no API call called SendMessageString. SendMessageString is simply an alias for SendMessage, using a particular declaration syntax that makes it (a little) easier to use if you are (only) trying to pass a string via lParam. You can however quite happily send strings without resorting to this alias.

Mind you, you have not helped yourself by trying to pass

Asc(strText)

which just passes the ASCII value of the first character of the string. i.e. the results you were seeing reflect exactly what your code says.

Assuming that you are using the standard declaration of SendMessage:

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

You can successfully send a string via WM_SETTEXT as follows:

SendMessage lng_hLogonUserIdBox, WM_SETTEXT, 0&, ByVal strText  

RE: Sendmessage / WM_SENDTEXT

(OP)
Ty strongm you are of course right I originally had this SendMessage declaration

Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal Msg As Long, wParam As Any, lParam As Any) As Long

which didn't work
so I found this on internet somewhere

Public Declare Function SendMessageString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Any) As Long

which did work and I never realized alias
however your declaration as posted didn't work either

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

I was getting the strange characters in the text box that had me trying the ASC() funtion you saw in my posted code (I have since removed it)

but I changed it to this and it worked

Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Any) As Long

inserting the ByVal in the last parameter fixed it
have never worked with window handles before and am just starting to get my head around the whole thing


 

"There is no pleasure in having nothing to do; the fun is having lots to do and not doing it.
." - Andrew Jackson
 

RE: Sendmessage / WM_SENDTEXT

>however your declaration as posted didn't work either

My declaration works fine. And is the correct declaration for this API call.

Please see my example call to see how you should call it rather than, as I suspect, using your own made-up call

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close