Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • 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!

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

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...I have tons of books, have book marked tons of tutorials, which have helped, but this forum has answered those "impossible to find" solutions. I am thrilled with this site..."

Geography

Where in the world do Tek-Tips members come from?
clapper62 (Programmer)
13 Apr 12 11:11
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))

 
clapper62 (Programmer)
13 Apr 12 12:01
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
 

strongm (MIS)
15 Apr 12 13:28
Not really
clapper62 (Programmer)
16 Apr 12 11:03
please elaborate am I doing something wrong here. It seems to work
strongm (MIS)
16 Apr 12 14:07
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  
clapper62 (Programmer)
16 Apr 12 15:24
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
 

strongm (MIS)
16 Apr 12 15:52
>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

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!

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