Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I display editable text (better explained inside!)

Status
Not open for further replies.

Insider1984

Technical User
Feb 15, 2002
132
US
Okay here is what I want to do: (in a MFC.exe dialog based app)


1. CLick a button
2. gets data from file (multiple lines)
3. Display the multiple lines in some sort of text edit box
4. IMPORTANT data must be displayed on multiple lines in same text edit box
5. Allow me to edit the text
6. Click save and program would paste text back into document.

Now I have done this with single line editing (aka normal text box). But which kind of text box (icon?) can I use to display multiple lines?

Thanks again for your help. I know my stuff only after I've played with it enough as I'm an engineer not a programmer =-)

we are only talking about 4-8 lines of 20 characters.


 
You use a standard Edit box.

Create an edit box; size it however large you need it.
Right-click it and choose "Properties".
On the "Styles" tab, check "Multiline" and "Want return".

To display multiline text properly, wherever you want a line break, just put a \r\n combination.
 
HELP AGAIN!

okay i setup the box but now it reads

&quot;Yo<BLACK SQAURE>Yo&quot;

when I write:

text = _T(&quot;Yo\rYo&quot;);

I also tried:

text = _T(&quot;Yo\nYo&quot;);

for the initial value
NO LUCK
Thanks again for the help.
 
I GOT IT! But WHY is the question!

I need to use both:

\r\n

I can't use:
\r
\n
or even
\n\r

so why does the order matter?
 
If you want to go to the next line,'\n' or '\r' alone wont work,however the combination of the two of them will. (&quot;\r\n&quot;)

so you should do: text = _T(&quot;Yo\r\nYo&quot;);
 
It has to do with Windows newline characters vs. the rest of the world's newline characters. All flavors of UNIX use just the \n as the newline character (DOS did as well). Windows, for some strange reason, uses the \r\n combination for its newline.

You can see an example of this with the following code:

FILE *f=fopen(&quot;something.txt&quot;,&quot;wb&quot;); //the &quot;b&quot; is for binary mode--no text filtering

fprintf(file,&quot;some \n stuff \n&quot;);
fclose(file);

Open this file in notepad and the line breaks will not display properly. This is because the file was written in binary mode. If you do not specify binary mode, the OS automatically translates \n into \r\n.

However, the file generated by those three lines of code will display perfectly on a UNIX box.

Hope this helps.
 
okay thanks for the explaination... now....

I'm reading a normal text file (which opens fine in Notepad) and trying to display it into the edit box previously discussed.

I get those stupid squares again. while reading in the file (which I do character by character) is their a way to add the \r before the \n?

here is the sample code I use to bring in the file

Code:
while(runtime == 0) 

{ //grabs file until it hits the end
      c = fgetc(oldfile);
      if(c != EOF)
	  {
	IDEA Add If statment here looking for c = EOL. Insert \r backstep k and continue
		  buffer[k] = c;//this adds the char c to the location k in the buffer string
		  k++;//this counts where inside buffer I really am.
      }
      else 
	  {
		  fclose(oldfile);
		  buffer[k] = '\0';
		  newstring = buffer;
		  a = newstring.Find(find1);
		  b = newstring.Find(find2);
		  text = newstring.Mid(a,b+sizer-a);
		  runtime=1;
      }//end else
	  	 
}//end while
 
thanks again...

I think writing it out on here allows me to understand it better. I figured it out:


while(runtime == 0)

{ //grabs file until it hits the end
c = fgetc(oldfile);

if(c != EOF)
{
if (c == '\n')
{
buffer[k] = placer;\\adds '\r'
k++;
}

buffer[k] = c;//this adds the char c to the location k in the buffer string
k++;//this counts where inside buffer I really am.
}
else
{
fclose(oldfile);
buffer[k] = '\0';
newstring = buffer;
a = newstring.Find(find1);
b = newstring.Find(find2);
text = newstring.Mid(a,b+sizer-a);
runtime=1;
}//end else

}//end while
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top