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

This topic is 4526 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

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?

Share on other sites
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.

Share on other sites
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

Share on other sites
Quote:
 Original post by Colin JeanneI 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

Share on other sites
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...

Share on other sites
Quote:
 Original post by johnnyBravoHow 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.

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 9
• 9
• 9
• 14
• 12
• Forum Statistics

• Total Topics
633302
• Total Posts
3011272
• Who's Online (See full list)

There are no registered users currently online

×