views:

45

answers:

1

Case in point : I've got a handle to a window (for instance, using the getForegroundWindow() API function). This window's got a textbox (possibly a richtext control). Would it be possible to modify the textbox's text through an Windows API call ? More specifically, I'd like to replace its text with some of my own.

+2  A: 

Once you have the handle to the parent window, you need to get the handle to the editcontrol.

If the editcontrol has a known, consistent identifier, use GetDlgItem to get its HWND. Otherwise you will need to resort to FindWindowEx.

Once you have the HWND of the editcontrol, you can use SendMessage to send a WM_SETTEXT message it. For rich text controls, use the EM_SETTEXTEX message.

sean e
That has same effect as a SetWindowText() call - Only the title bar's text is changed.
shadeMe
I've just confirmed - The target is a RichText control.
shadeMe
Will try. Thanks for clarifying.
shadeMe
For rich text controls, use EM_SETTEXTEX http://msdn.microsoft.com/en-us/library/bb774284%28VS.85%29.aspx
Vulcan Eager
@Angel: good point, answer updated.
sean e