Using SendMessage to send text

myee
myee used Ask the Experts™
on
I need to send an "enter" string to a command button in another App (WindowsXP). This must happen overight while the screen is locked, so I cannot use Sendkeys or keybd_event (neither works when the screen is locked).

I would be grateful for an example of how to do this, or accomplish the same thing.


Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
in vb, 'enter' is chr(13)
did u tried SendMessage API..

Author

Commented:
appllenie,

"enter" was just a sample. This issue issue is that when the screen is locked the Sendkeys command is inop.

ananth666,

I actually was hoping for an example of how to do what you just said (use SendMessage API or similar to send a string to a form control in another app). I do not yet know if that will work when the screen is locked.

Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
Here is a solution I found:

1) Get the Windows Handle on the dialogue box using FindWindow - FindWindow(vbNullString, sProcess)

2) Send a click to the  control:

Public Sub SendClick(hwndHandle As Long, sControlName As String, sControlCaption As String)

    Dim imclass As Long, Button As Long
    Dim t1 As Long, t2 As Long
    'Button = FindWindowEx(hwndHandle, 0&, "ThunderCommandButton", vbNullString)
    Button = FindWindowEx(hwndHandle, 0&, sControlName, sControlCaption)
    'Button = FindWindowEx(imclass, Button, "ThunderCommandButton", vbNullString)


    Call SendMessageCallback&(Button, BM_SETSTATE, 0, ByVal 0&, t1, t1)
    Call SendMessageCallback&(Button, WM_KEYDOWN, VK_SPACE, 0&, t1, t1)
    Call SendMessageCallback&(Button, WM_KEYUP, VK_SPACE, 0&, t1, t1)
    Call SendMessageCallback&(Button, WM_RBUTTONDBLCLK, VK_SPACE, 0&, t1, t1)
    Call SendMessageCallback&(Button, BM_SETSTATE, 1, ByVal 0&, t1, t1)
    Call SendMessageCallback&(Button, WM_KEYUP, VK_SPACE, 0&, t1, t1)
End Sub

The declarations and constants are not shown
Author of the Year 2009

Commented:
myee, an EE Moderator will handle this for you.
Moderator, my recommended disposition is:

    Refund points and save as a 0-pt PAQ.

DanRollins -- EE database cleanup volunteer
Commented:
Per recommendation,

PashaMod
CS Moderator

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial