Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sendmessage / WM_SENDTEXT

Status
Not open for further replies.

clapper62

Programmer
Apr 17, 2003
113
US
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))

 
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
 
please elaborate am I doing something wrong here. It seems to work
 
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
 
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
 
>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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top