CEdit multiline

I read the contents of a file and store them in a CStringArray with
each element of the CStringArray containing one line of text.

then I use the following routine to display the file contents into a
multiline CEdit control, however it display only one line of text
Any suggestions will be appreciated.

 int nLines = m_strFileDataArray.GetUpperBound();;
 CString temp, temp1;
 temp.Empty();

 for (int i = 0; i != nLines; i++)
 {
  temp += m_strFileDataArray[i];
  temp = "\r\n";
  }
m_EditWnd.SetWindowText(temp);


0
prg (15)
2/1/2004 5:07:45 AM
vc.mfc 33608 articles. 0 followers. Follow

8 Replies
900 Views

Similar Articles

[PageSpeed] 53

/r/n should give a line break. You need to make sure that your control has multi-line
style turned on(ES_MULTILINE).

-- 
Ajay Kalra [MVP - VC++]
ajaykalra@yahoo.com



"prg" <prg@prg.prg> wrote in message news:bvi1hv$33q$1@yeppa.connect.com.au...
| I read the contents of a file and store them in a CStringArray with
| each element of the CStringArray containing one line of text.
|
| then I use the following routine to display the file contents into a
| multiline CEdit control, however it display only one line of text
| Any suggestions will be appreciated.
|
|  int nLines = m_strFileDataArray.GetUpperBound();;
|  CString temp, temp1;
|  temp.Empty();
|
|  for (int i = 0; i != nLines; i++)
|  {
|   temp += m_strFileDataArray[i];
|   temp = "\r\n";
|   }
| m_EditWnd.SetWindowText(temp);
|
|

0
ajaykalra (6840)
2/1/2004 6:40:25 AM
the multiline option is selected  but the thing is not working

"Ajay Kalra" <ajaykalra@yahoo.com> wrote in message
news:e88lH5I6DHA.488@TK2MSFTNGP12.phx.gbl...
> /r/n should give a line break. You need to make sure that your control has
multi-line
> style turned on(ES_MULTILINE).
>
> -- 
> Ajay Kalra [MVP - VC++]
> ajaykalra@yahoo.com
>
>
>
> "prg" <prg@prg.prg> wrote in message
news:bvi1hv$33q$1@yeppa.connect.com.au...
> | I read the contents of a file and store them in a CStringArray with
> | each element of the CStringArray containing one line of text.
> |
> | then I use the following routine to display the file contents into a
> | multiline CEdit control, however it display only one line of text
> | Any suggestions will be appreciated.
> |
> |  int nLines = m_strFileDataArray.GetUpperBound();;
> |  CString temp, temp1;
> |  temp.Empty();
> |
> |  for (int i = 0; i != nLines; i++)
> |  {
> |   temp += m_strFileDataArray[i];
> |   temp = "\r\n";
> |   }
> | m_EditWnd.SetWindowText(temp);
> |
> |
>


0
prg (15)
2/1/2004 9:44:29 AM
prg wrote:
>>| I read the contents of a file and store them in a CStringArray with
>>| each element of the CStringArray containing one line of text.
>>|
>>| then I use the following routine to display the file contents into a
>>| multiline CEdit control, however it display only one line of text
>>| Any suggestions will be appreciated.
>>|
>>|  int nLines = m_strFileDataArray.GetUpperBound();;
>>|  CString temp, temp1;
>>|  temp.Empty();
>>|
>>|  for (int i = 0; i != nLines; i++)
>>|  {
>>|   temp += m_strFileDataArray[i];
>>|   temp = "\r\n";
>>|   }
>>| m_EditWnd.SetWindowText(temp);

Simple error: You need += instead of = for "\r\n"


-- 
Scott McPhillips [VC++ MVP]

0
scottmcp8856 (490)
2/1/2004 2:25:12 PM
"Scott McPhillips [MVP]" <scottmcp@mvps.org.nothere> wrote in message
news:O3WfG%23M6DHA.2264@tk2msftngp13.phx.gbl...
> prg wrote:
> >>| I read the contents of a file and store them in a CStringArray with
> >>| each element of the CStringArray containing one line of text.
> >>|
> >>| then I use the following routine to display the file contents into a
> >>| multiline CEdit control, however it display only one line of text
> >>| Any suggestions will be appreciated.
> >>|
> >>|  int nLines = m_strFileDataArray.GetUpperBound();;
> >>|  CString temp, temp1;
> >>|  temp.Empty();
> >>|
> >>|  for (int i = 0; i != nLines; i++)
> >>|  {
> >>|   temp += m_strFileDataArray[i];
> >>|   temp = "\r\n";
> >>|   }
> >>| m_EditWnd.SetWindowText(temp);
>
> Simple error: You need += instead of = for "\r\n"

made the necessary changes however the "temp" variable does not add the
stored elements
I thing is something wrong with "+=" directive, I just do not know what else
to do, I even
removed the line "temp += "\r\n"" and it still does not work

>
>
> -- 
> Scott McPhillips [VC++ MVP]
>


0
prg (15)
2/1/2004 9:51:23 PM
prg wrote:
>>>>|  int nLines = m_strFileDataArray.GetUpperBound();;
>>>>|  CString temp, temp1;
>>>>|  temp.Empty();
>>>>|
>>>>|  for (int i = 0; i != nLines; i++)
>>>>|  {
>>>>|   temp += m_strFileDataArray[i];
>>>>|   temp = "\r\n";
>>>>|   }
>>>>| m_EditWnd.SetWindowText(temp);
>>
>>Simple error: You need += instead of = for "\r\n"
> 
> 
> made the necessary changes however the "temp" variable does not add the
> stored elements
> I thing is something wrong with "+=" directive, I just do not know what else
> to do, I even
> removed the line "temp += "\r\n"" and it still does not work

Can you use the debugger to learn anything more than "it still does not 
work?"  You probably have several problems, and need to analyze things 
step by step to find out what works, what doesn't, and fix things one 
tiny little problem at a time.

Is there data in m_strFileDataArray[0]; ?
Is there data in m_strFileDataArray[1]; ?

Put in a temporary line like CString strTest = m_strFileDataArray[i];

....and look at strTest with the debugger to check these things.

What is in temp after each step through the loop ?  Use the debugger to 
single step through the loop and find out.

Is nLines the correct number ?  Check it and see!
( I see another bug there: GetUpperBound() does not return the
   number of lines. )

Get the idea?  Start simple.  Advance inch by inch.  Check everything.

-- 
Scott McPhillips [VC++ MVP]

0
scottmcp8856 (490)
2/1/2004 10:48:39 PM
"Scott McPhillips [MVP]" <scottmcp@mvps.org.nothere> wrote in message
news:Ow49aXR6DHA.2952@tk2msftngp13.phx.gbl...
> prg wrote:
> >>>>|  int nLines = m_strFileDataArray.GetUpperBound();;
> >>>>|  CString temp, temp1;
> >>>>|  temp.Empty();
> >>>>|
> >>>>|  for (int i = 0; i != nLines; i++)
> >>>>|  {
> >>>>|   temp += m_strFileDataArray[i];
> >>>>|   temp = "\r\n";
> >>>>|   }
> >>>>| m_EditWnd.SetWindowText(temp);
> >>
> >>Simple error: You need += instead of = for "\r\n"
> >
> >
> > made the necessary changes however the "temp" variable does not add the
> > stored elements
> > I thing is something wrong with "+=" directive, I just do not know what
else
> > to do, I even
> > removed the line "temp += "\r\n"" and it still does not work
>
> Can you use the debugger to learn anything more than "it still does not
> work?"  You probably have several problems, and need to analyze things
> step by step to find out what works, what doesn't, and fix things one
> tiny little problem at a time.
>
> Is there data in m_strFileDataArray[0]; ?

yes

> Is there data in m_strFileDataArray[1]; ?

yes

>
> Put in a temporary line like CString strTest = m_strFileDataArray[i];
>
> ...and look at strTest with the debugger to check these things.
>
> What is in temp after each step through the loop ?  Use the debugger to
> single step through the loop and find out.

only the first element of the CStringArray; it does not add the other
elements of the
CStringArray to the initial value stored in the "temp";

the CStringArray has all the lines in the file, I've checked that

>
> Is nLines the correct number ?  Check it and see!
> ( I see another bug there: GetUpperBound() does not return the
>    number of lines. )

changed to
int nLines = m_strFileDataArray.GetSize();

>
> Get the idea?  Start simple.  Advance inch by inch.  Check everything.
>
> -- 
> Scott McPhillips [VC++ MVP]
>


0
prg (15)
2/1/2004 11:29:45 PM
prg wrote:
> I read the contents of a file and store them in a CStringArray with
> each element of the CStringArray containing one line of text.
> 

Any reason why you're doing this to read the "file", ie, why not use
CFile class to read the file and then display it?

- Zilla


0
2/2/2004 3:00:07 PM
"Zilla" <zilla62XSPAM@bellsouth.net> wrote in message
news:YBtTb.131$Hc1.60@fe02.usenetserver.com...
> prg wrote:
> > I read the contents of a file and store them in a CStringArray with
> > each element of the CStringArray containing one line of text.
> >
>
> Any reason why you're doing this to read the "file", ie, why not use
> CFile class to read the file and then display it?
>
> - Zilla

First of all, how do you go about implementing such a task?
However, I need the file contents to be available for further processing
one line at the time.

However, I wish to thank all of you for your contributions and
generousity and upon following the advice given by
Scott McPhillis, I managed  to track down the motherf...ng bug
to the directive used to load the CStringArray.

problem fixed.



0
prg (15)
2/3/2004 3:18:05 AM
Reply:

Similar Artilces:

CEdit Control
I have an SDI app a with CFormView. The CFormView has multiple edit controls on it. What is the best way to save the data for the conrol ie what message do I need to handle. There are one case I'm concerned about: 1. The user has selected save or exit from the top menu. I have tried handling the kill focus message for the control but if you have make changes to the edit box and have not exited it before doing a File | Save the kill focus message is not send and I don't save the data. I don't really want to update on every keystroke in the edit control since I only care ...

How to change the CEdit's caret?
Hi, I have an edit control for which I can change its font depending on a checkbox status. How can I change the caret back and forth depending on which font is set in the CEdit control? I appreciate any help. Thanks, Geo I don't think this is possible for a CEdit. If I were trying it, I'd subclass the CEdit and override the OnSetFocus/OnKillFocus, and do caret manipulations there, but at this point you're trying to deal with fooling the CEdit into doing what you want, and that is likely to be unsuccessful. joe On Fri, 25 Nov 2005 19:46:02 -0800, Geo <Geo@discuss...

CEdit
Hi All, I would like to change the appereance of CEdit's buttons. Ideally, I would like to replace them with my own buttons (derived from CBitmapButton). I know all about the limitations of CEdit in terms of attempting to change the way it draws itself so before I even try to do something like this I would like to know if anyone here has any experience with that and if this scenario is even supported by CEdit. Furthermore, I would also like to draw its scrollbars. If I can't take over the drawing of its buttons and scroll bars, is it at least possible to change thei...

Subclassing CEdit in CComboBox
Hello, I'm trying to make a CComboBox derived control where the text shown in the selection box is different from any text in the combo's list. I've been following Microsoft Knowledge Base Article - 174667 (HOWTO: Subclass CListBox and CEdit Inside of CComboBox), which suggests using OnCtlColor() to get a handle for the edit control inside the combo box. My CMyComboBox is created dynamically at runtime, and I've noticed that their approach only works when the combo box is created with the CBS_DROPDOWN style. With CBS_DROPDOWNLIST the OnCtlColor() handler is never called at a...

appending to CEdit
I have a CEdit control and I want to append text to it as follows: void CSerialPortDlg::debugf(char* format, ...) { char buf[4096]; // should be big enough va_list arglist; va_start( arglist, format ); vsprintf( buf, format, arglist ); va_end( arglist ); if( GetSafeHwnd() && m_edit.GetSafeHwnd() ) { m_edit.LineScroll( m_edit.GetLineCount() ); m_edit.SetSel( -1, 0, TRUE ); m_edit.ReplaceSel( buf ); } } This works fine until there is a lot of text in the CEdit control. After, oh I don't know, maybe 64k of data or so, it no longer adds any...

Tab character in a multiline text edit field?
Hi! This is probably a stupid, question, but: When creating a dialog with a multiline text edit field, I am unable to make the field insert the tab character when I press the tab key, it only selects all text. Or rather, it wants to go to the next control, but as the edit field is the only control... well, you know what I mean. This should be a normal text-file editor. What to do about this? Hoping for a quick response, Morten "Morten Aune Lyrstad" <too@much.spam> wrote in message news:qqkGc.61$GY2.13412@juliett.dax.net... > Hi! This is probably a stupid, question, but: ...

How to Set/Change Transparency to CEdit control?
Hi, How to set/change Transparency to Custom Edit control. Can I use SetLayeredWindowAttributes() to set alpha factor for CEdit control? Can I use WS_EX_LAYERED style to child (CEdit) controls? Or should I use GDI+ library feature (Gdiplus::SolidBrush(Gdiplus::Color()). At present both ways are not working for me. Since the edit control is drawn with GDI, invoking a GDI+ mechanism is not going to be terribly successful. While you might consider subclassing the edit control and returning a NULL_BRUSH, this will not produce satisfactory results because edit controls are drawn with SetBkMode(OP...

CEdit white
I have some read only CEdit controls on a dialog, but they appear grey. I would like them to be white. I tried subclassing CEdit and adding the following method (m_brBackgroundBrush is a plain white brush), but they are still grey - any ideas? Should I overwrite the OnPaint or OnDraw method perhaps? BOOL CEditWhite::OnEraseBkgnd(CDC* pDC) { BOOL returnVal = CEdit::OnEraseBkgnd(pDC); CRect rect; GetClientRect(&rect); // Tile the watermark bitmap over the screen pDC->FillRect(&rect, &m_brBackgroundBrush); return returnVal; } "GT" <ContactGT_removeme_@...

CEdit PreSubclassWindow Problem
Hi Do anyone know why in derived class of CEdit with PreSubclassWindow that uses a SetWindowText while( m_hWnd is valid for both conditions) it works fine if subclassed with DLG items but if it was created ,it generated Diveded By Zero Access Violation. this brief code makes scenario. thanks in advance. //Header class CMyEdit : public CEdit { public: CMyEdit(){} virtual ~CMyEdit(){} ..... protected: virtual void PreSubclassWindow(); }; //Source void CMyEdit::PreSubclassWindow() { SetWindowText("Preset Text"); } // class CTestDlg : public CDialog { ... CMyEdit m_Edmp; ......

About CEdit
Is there any component like CEdit that accepts only numbers? And how can I get others components in VC6, like listboxes, combos, etc? Thanks in advance. Leonardo Kasperavicius If your using the Dialog Editor, not creating the controls dynamically, the easiest way would be to set the number flag in the properties for the field you want to be numeric only. You get the other controls by selecting them from the control toolbar in the dialog editor as well. If you are creating them dynamically, you would use CListBox, CComboBox, CStatic, CButton, etc... HTH -- ============ Frank Hickman Nobl...

CEdit Background
When I make CEdit class Read Only, the background turns grey. How can I make it Read Only and have a white background? (Much like the compilation output window in VS Studio). Thanks. Jess You need to handle WM_CTLCOLORSTATIC for a readonly edit control. ----- Ajay Kalra ajaykalra@yahoo.com maybe WM_CTLCOLOREDIT "Ajay Kalra" <ajaykalra@yahoo.com> ??????:1142196362.062801.264450@j33g2000cwa.googlegroups.com... > You need to handle WM_CTLCOLORSTATIC for a readonly edit control. > > ----- > Ajay Kalra > ajaykalra@yahoo.com > WM_CTLCOLOREDIT does not w...

CEdit SetWindowText rediculously slow
Hi, I have an MFC application, runing on XP. When I do SetWindowText() on an EditControl, it takes >950 ms This seems rediculous, even when reallocation takes place. What can cause this. Is there a faster way to update the text ? Greetings, Rob. "Rob" <Rob@discussions.microsoft.com> wrote in message news:E045587E-6F5D-4E5F-A5DF-85367691CE57@microsoft.com... > > Hi, > I have an MFC application, runing on XP. > When I do SetWindowText() on an EditControl, it takes >950 ms > This seems rediculous, even when reallocation takes place. > > What can c...

DLL CEdit::Create() Error
I have a class, CMEdit, which inherits from CEdit and when I call my OnCreate function, I simply call CEdit::Create. This class is a private member of another class, CNodeConfig, and when that class is in th emfc application itself, it runs fine. However, when I put it into a dll and call the same thing, I get an assert error in wincore.cpp on line 888 which is: LRESULT AFXAPI AfxCallWndProc(CWnd* pWnd, HWND hWnd, UINT nMsg, WPARAM wParam = 0, LPARAM lParam = 0) { _AFX_THREAD_STATE* pThreadState = _afxThreadState.GetData(); MSG oldState = pThreadState->m_lastSentMsg; // save f...

Hiding CEdit derived window !
I have a CEdit derived object "m_myedit" on my dialog box and i want to hide or show it dynamically. How can this be done? m_myedit.ShowWindow(SW_HIDE); //hide m_myedit.ShowWindow(SW_SHOWNORMAL); //show Janusz U�ytkownik "Bredal Jensen" <bredal@jensen.dk> napisa� w wiadomo�ci news:OLKDKblmEHA.2880@TK2MSFTNGP14.phx.gbl... > > I have a CEdit derived object "m_myedit" on my dialog box and i want to > hide or show it dynamically. > How can this be done? > > right thanks... "Janusz Grabis" <erfan@poczta.onet.pl> skre...

'SendMessage' is not a member of CEdit, See declaration of 'CEdit'
Can any one tell me what makes my compiler think that. Its making me crazy !! I am using VC++ 6.0. thanks, prakash It's not a member of CEdit but it is a member of it's base class CWnd. "PSN" <prakash437@gmail.com> wrote in message news:1149770896.076143.94070@u72g2000cwu.googlegroups.com... > Can any one tell me what makes my compiler think that. Its making me > crazy !! I am using VC++ 6.0. > > thanks, > prakash > Kurt wrote: > It's not a member of CEdit but it is a member of it's base class CWnd. thats right ... But ist the crite...

OnMouseOver for CEdit and CButton
How may I catch the OnMouseOver event when I have cursor on CEdit and CButton controls ? In control events I can't find this. When I moving curson over CEdit box I want display (in other control) some information about data content in CEdit. How to do it ? MSVS 2005. On 27 Mar 2007 07:29:46 -0700, "Mammoth" <cactusek@gmail.com> wrote: >How may I catch the OnMouseOver event when I have cursor on CEdit and >CButton controls ? In control events I can't find this. >When I moving curson over CEdit box I want display (in other control) >some information about d...

CEdits and CStrings
While going through one of my projects and applying variable names to some of the controls I generally found that doing so for controls like buttons usually defaulted to a control type of CButton or such. But with CEdits it would default to a value type of CString. Is this some sort of shortcut to accessing the text within a CEdit control rather than having to extract the text before using it? Or is this some sort of behavior of the compiling environment that I just need to accept? Thanks, Lilith The default *control* for it is CEdit, CString is the default variable type, which is added ...

CEdit and \n
I have a CEdit control that loads a text file with multiple lines. Instead of the text box showing a new line it shows the little black box. I set the multi-line property to true, why is this behavior happening Thank "Mark" <anonymous@discussions.microsoft.com> wrote in message news:C41E31D2-7ACD-463D-B0D3-A16A128B053D@microsoft.com... > I have a CEdit control that loads a text file with multiple lines. Instead of the text box showing a new line it shows the little black box. I set the multi-line property to true, why is this behavior happening? > Thanks I think the ed...

where to create CEdit again
I created a CEdit control in OnInitUpdate, but the postion is fixed. I want it to be repositioned again when CView is resized. What is the right place to create this control again? I tried onDraw, the control is blinking all the times. thanks pat/ simple use CView::OnSize(int cx,int cy) if(GetSafeHwnd()) { if( myEdit.GetSafeHwnd()) myEdit.MoveWindow(CRect(0,0,cx,cy)); } } reg -Jibesh ------------------------------------------------------------------------- FIGHT BACK AGAINST SPAM! Download Spam Inspector, the Award Winning Anti-Spam Filter http://mail.giantcompany.com &...

Copy/Paste in CMyEdit that inherits from CEdit
Hi everyone, I created a new class CMyEdit that inherits from CEdit. Then I defined an edit control in my dialog to this type. So basically the only thing I changed is using the class CMyEdit instead of CEdit for the edit control. The problem is that when I run the program, I can't copy/paste anymore in the edit control using the keyboard (Ctrl+C and Ctrl+V). I have to do it only with the mouse. Note that CMyEdit does not define any new function or override or overload any function from CEdit. I have just created it with the Add Class Wizard and tested my code. What should I do t...

CEdit::SetSel() did not work
Hi, I have a CEdit control which I called its method SetSel (0, -1) but no text is selected. My CEdit control is read only. Am I missing something? Thanks a lot, Mike Try SetFocus() before calling SetSel(). Something like YourEditControl.SetFocus(); YourEditControl.SetSel(0,-1); -- Cheers Check Abdoul [VC++ MVP] ----------------------------------- "Mike" <anonymous@discussions.microsoft.com> wrote in message news:143b01c4cc2f$3d758e20$a501280a@phx.gbl... > Hi, > > I have a CEdit control which I called its method SetSel > (0, -1) but ...

is it a bug of CEdit?
I use resouce edit to define a CEdit control which only accept digit number. I found,when I input char to the edit by typing ,it works well,only accept digit. but I still can use ctrl + c to paste non-digit char into it. to work around this problem,I check the input every time the content of the cedit vary which induce an event to report the change >I found,when I input char to the edit by typing ,it works well,only accept >digit. >but I still can use ctrl + c to paste non-digit char into it. It is a documented quirk! ;) See ES_NUMBER here: http://msdn.microsoft.com/librar...

paste multiline text to a single cell-Excel 97
I wrote a little macro to do this with the .GetFromClipboard method and it works fine, but many users will need to do this in the org and I'm wondering if there's a simpler method. Based on other recommendations I tried the replace Alt+0010 method and got an error message that the 'Formula is too long.' Is there a simpler method? Thanks! Cindy Maybe they could just paste into the formula bar. But I don't think I understand the real question. cgbikes wrote: > > I wrote a little macro to do this with the .GetFromClipboard method and it > works fine, but man...

Multilanguage support for CEdit
Hi all, My develop environment is WinXP with VC6.0. How to support multilanguage for Edit box? I test with JPN, ELL, THA, RUS, the edit box can not show the character correctly. I don't want to change my progarm to unicode. Is there any other solution? I had tried SetFont(), edit RC file (code_page....), add native font control, but all without lucky. Please help....Thanks a lot. Justin On Nov 15, 2:41 am, Justin_Fang <ccf...@gmail.com> wrote: > Hi all, > > My develop environment is WinXP with VC6.0. > > How to support multilanguage for Edit box? I test with JPN, ...

Scroll with CEdit
On a CEdit new data is attached. I want to see the new data, therefore the scroll position in this CEdit should remain on the bottom. How can I solve this without scrolling to bottom whenever the content of CEdit has changed (this slows down my app and is really unsightly? I believe you can call LineScroll() to do this: http://msdn2.microsoft.com/en-us/library/a6yzcse2.aspx However if you are only putting lines into the control (like a status line or something) you may want to consider using a CListBox or CListCtrl instead since it's easier to add and replace lines. Another thing...