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
2010-03-04 06:34:02
That has same effect as a SetWindowText() call - Only the title bar's text is changed.
shadeMe
2010-03-04 07:11:19
I've just confirmed - The target is a RichText control.
shadeMe
2010-03-04 07:35:19
Will try. Thanks for clarifying.
shadeMe
2010-03-04 09:42:24
For rich text controls, use EM_SETTEXTEX http://msdn.microsoft.com/en-us/library/bb774284%28VS.85%29.aspx
Vulcan Eager
2010-03-04 14:35:29
@Angel: good point, answer updated.
sean e
2010-03-04 16:13:53