0

How to use the windows API to communicate with other applications?

For example, another application has a textbox, I have already set mouse on there using mouse_event, but I don't know how to send a string to it, and display the string on that textbox?

pb2q
  • 58,613
  • 19
  • 146
  • 147
  • http://msdn.microsoft.com/en-us/library/windows/desktop/ms646310%28v=vs.85%29.aspx – SLaks Sep 30 '12 at 18:43
  • I would just use `SendMessage` with `EM_SETTEXT` or call `SetWindowText`. I believe only one of them is appropriate when the textbox isn't yours, but I forget which. – chris Sep 30 '12 at 18:49
  • 1
    Why don't you use automation interfaces rather than moving mouse. The mouse isn't yours to move. – David Heffernan Sep 30 '12 at 19:10
  • What application are you trying to communicate with? Some applications like the Microsoft Office programs have automation interfaces you can use (that David Heffernan alludes to) that are way more reliable to use than hacking around the mouse. – In silico Oct 01 '12 at 05:06
  • I wonder how often this same question gets asked? – Deanna Oct 01 '12 at 11:05

1 Answers1

1

Thank you all! I have made it by using keybd_event, here is my code:

keybd_event((BYTE)VkKeyScan(lpMsg[i-1]), 0, 0, 0);
keybd_event((BYTE)VkKeyScan(lpMsg[i-1]), 0, KEYEVENTF_KEYUP, 0);

I have another question here, because the window I want to send text to isn't the normal ones, it's an internet form, which content has been downloaded from internet. So I cannot use SetWindowText or something else, but to simulate the keyboard input.

My question is: A form contains many buttons and textboxes and labels and something else. The function EnumChildWindows(hwndGame, EnumChildProc, 0); Will continues until the last child window is enumerated or the callback function returns FALSE. What are Child windows? Are those buttons and textboxes on this form ??

Jake1164
  • 12,291
  • 6
  • 47
  • 64