c++ win32: How to concat text onto a window's text?

Started by
4 comments, last by Zahlman 17 years, 9 months ago
Hi, with c++ win32, I've got two window edit controls, 'in' and 'out'. Basically in pseudo code I want to do this: out.text+=in + "\r\n"; How would I do this?
Advertisement
I believe the easiest way is to use EM_SETSEL to move the selection to the very end of the edit and then use EM_REPLACESEL to replace that empty selection at the end. This will effectively append your text.
for the 'in' control, you must respond to the EN_CHANGE (or is it EN_UPDATE) notification message (i forget which one, there are two of them, i can't recall which one off the top of my head). one of them gets called whenever and after an edit control's text has been changed. for 'in's EN_CHANGE, just call GetWindowText for 'in', grab the text, modify it, and then store it in 'out.'
Y-Go
Quote:Original post by Colin Jeanne
I believe the easiest way is to use EM_SETSEL to move the selection to the very end of the edit and then use EM_REPLACESEL to replace that empty selection at the end. This will effectively append your text.


How would I move the select the very end?


As a test I tried this, but OutputDebugString returns an error, whats wrong?
char*a=0;GetWindowText(in, a, GetWindowTextLength(in));OutputDebugString(a);


thx
Here's what I posted in a similar thread a while ago:
void AppendData(HWND pTargetHandle, std::string const & rData, bool bNewLine = true){	if(!pTargetHandle || rData.empty())		return void();	LRESULT iDummy = SendMessage(pTargetHandle, WM_GETTEXTLENGTH, NULL, NULL);	if(iDummy + static_cast <LRESULT> (rData.size()) > SendMessage(pTargetHandle, EM_GETLIMITTEXT, NULL, NULL))		SendMessage(pTargetHandle, EM_LIMITTEXT, iDummy + rData.size(), NULL);	SendMessage(pTargetHandle, EM_SETSEL, iDummy, iDummy);	SendMessage(pTargetHandle, EM_REPLACESEL, FALSE, reinterpret_cast <LPARAM> (rData.c_str()));	if(bNewLine)		AppendData(pTargetHandle, "\r\n", false);}

Hope that helps...
Quote:Original post by johnnyBravo
How would I move the select the very end?


Well, you can specify a position, right? And you can grab the text, right? And having a chunk of text, you can determine its length, right?

Quote:
As a test I tried this, but OutputDebugString returns an error, whats wrong?
*** Source Snippet Removed ***

thx


Note: the following advice comes from not reading any of the documentation, but simply "knowing how these things work". You really should look up the documentation yourself.

You were asked for an "out parameter", a pointer to a buffer into which to write the string. You cannot pass a null pointer, because the function will either reject that out of hand (if it's smart) or mindlessly try to write stuff at memory location 0 and (likely) crash.

This topic is closed to new replies.

Advertisement