Solved

Multiline Text Area

Posted on 2001-09-13
4
515 Views
Last Modified: 2013-12-03
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
Comment
Question by:yccheok
  • 2
  • 2
4 Comments
 
LVL 7

Expert Comment

by:peterchen092700
ID: 6481604
To append text, set selection to end of the box, and call ReplaceSel with the text to append.
0
 

Expert Comment

by:chandas
ID: 6486850
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
 
LVL 7

Accepted Solution

by:
peterchen092700 earned 10 total points
ID: 6486957
>> 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
 

Expert Comment

by:chandas
ID: 6486971
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now