[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 558
  • Last Modified:

Multiline Text Area

I have a edit control  (I am using c/sdk) which i tend to make it as text area to display my program message. the control has properties as:
vertical scroll, auto vscroll, want return.

I was wondering how can i add text in multiple line. for instance, i use
char *buf1 = "hello\r\n";
char *buf2 = "hai\r\n";
SendMessage(GetDlgItem(hDlg, IDC_CON_CON), WM_SETTEXT, 0, (LPARAM) buf1);

SendMessage(GetDlgItem(hDlg, IDC_CON_CON), WM_SETTEXT, 0, (LPARAM) buf2);

it can only display
hai

where i want
hello
hai


Pls help. If possible, do e-mail the solution to my mail box
yccheok@yahoo.com

since i don't have any internet access in this few day and it may take my sometimes to search back my message :)

thanks

regards
yccheok

0
yccheok
Asked:
yccheok
  • 2
  • 2
1 Solution
 
peterchen092700Commented:
To append text, set selection to end of the box, and call ReplaceSel with the text to append.
0
 
chandasCommented:
Hi there, this question has been asked and answered before. I can't search for the link but anyway, last time I said, the easiest way to do this is to use a function called InsertText(int a, LPSTR lpstr, BOOL b)

a = the zero based index of the position in the text area where you want to insert the text.

b = the string you want to insert

c = TRUE (most likely) it just specifies whether or not you want the insertion re-drawn (or something like that)

You cannot use WM_SETTEXT because it is designed to replace all the text with the current text. That's why you are seeing only your last entry.

Regards

Senkwe
0
 
peterchen092700Commented:
>> InsertText(int a, LPSTR lpstr, BOOL b)
Where is this function declared? MSDN doesn't know this (in this context)

yccheok: any comments? anything else you need?

(btw. you would have gotten code if you had offered the 50pts for an easy question)

Peter

0
 
chandasCommented:
Hi Peter, sorry...I use WTL (and hence I tend to forget that not everybody does) so InsertText is defined as follows for an edit or richedit control...


int InsertText(long nInsertAfterChar, LPCTSTR lpstrText, BOOL bCanUndo = FALSE)
     {
          int nRet = SetSel(nInsertAfterChar, nInsertAfterChar);
          ReplaceSel(lpstrText, bCanUndo);
          return nRet;
     }

So your solution works great if you're not using WTL. Funny thing is I answered the exact same question to a guy that was not using WTL and he gave me the points.

Anyway, yccheok, you can simply copy the body of this function and adapt it to your code...but give the points to Peter because his solution is more or less the same except that it won't allow you to place text arbitrarily inside the text area. But that's easily done as you can see.

Regards

Senkwe.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now