Jump to content
  • Advertisement
Sign in to follow this  
johnnyBravo

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

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

If you intended to correct an error in the post then please contact us.

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 this post


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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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 this post


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

Share this post


Link to post
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 this post


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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!