Edit Box Diplaying Problem

VC++5 WinNT Edit Box - Stop showing after some long text.

Do anyone knows how to "flush" & "reset an edit Box used in a dialog?  My application captued text & besides storing them onto database, I would also like to display what I have captured onto the edit box in the dialog.  In a sort-of "stress" test, by simulating a large text file (actually is about 42K text file only), the edit box showed up to around 3/4 of the total file only :(

The capturing & storing process still carry on in the background, so I guess it seems that the edit box has run out of memory.  Retry running the process several times, the edit box will always stop showing at the same position.  

I try to check for the "error allocating memory" event for the edit box but it doesn't seems to go to that function. (Coz, the MessageBox() code is not executed.)  So I am puzzled, can any one help ?

Thanks alot :)
sllsglAsked:
Who is Participating?
 
nietodConnect With a Mentor Commented:
Answer coming.
0
 
nietodCommented:
You can use SetWindowText() to change the text stored in the edit control.
0
 
nietodCommented:
I believe that that edit box's have a 64K limit.  If they store wide characters that might be a 32K (in characters still 64K of memory) limit.  Are you stopping at 32k?  I beleive the RTF control does not have this limit.
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
jtwine100697Commented:
  Also note that single line edit controls stop at 32Kb, and in order to obtain the 64KB limit with multiline edit controls, you might have to provide your own buffer.

   "nietod"'s suggestion of SetWindowText() if correct.  You can set (and erase!) text in an edit control with it.

   If you are going to be displaying large amounts of data, using the Rich Edit Control is the way to go!

-=- James.
0
 
nietodCommented:
Then as james suggested, but didn't spell out.  Your edit control will stop at 32K not at 64K as I had thought.   This true even if it uses 8 bit characters.  
0
 
sllsglAuthor Commented:
So there seems to be no way to "flushes" the edit box & forces it to restart at the beginning position, am I right?

So, if I substitute edit box with a ListBox, do anyone knows if a ListBox has its size limitation as well?  I tried using ListBox after someone told me that there is a ResetContent() function to use for it when it grows too large.

BTW, for a listbox's scroll bar, how can I make it auto VScroll like an edit box?

Thanks for any help & suggestions :)
0
 
nietodCommented:
What do you mean by flush and restart at the beginning?  I suspect there is, I just don't know what you want.

What do you mean by "auto  VScroll"?
0
 
nietodCommented:
Do you mean you want the list box's scroll bar to always appear, even if scrolling is not necessary?  If so, then you want the LBS_DISABLENOSCROLL style.


0
 
nietodCommented:
List boxes do have a limit to the amount they can store.  I don't know what the limit is.  I don't know if the limit is in terms of the number of items or in terms of the total spaced required by the items.
0
 
jtwine100697Commented:
  If you want to ERASE the contents of the Edit Control, you can use CEdit::SetWindowText( afxEmptyString ).

   If you want to REPLACE the contents of the Edit Control, you can use CEdit::SetWindowText( "Text To Replace With" ).

   If you want to keep reusing the Edit Control for the display of information, just use CEdit::SetWindowText(...) with the information you want to display.

-=- James.

0
 
sllsglAuthor Commented:
Thanks James, your help is greatly appreciated & of course, thanks to the others too who gave some suggestions:)

As for the Auto V-Scroll portion, what I actually want, is that if I keep on adding new items to the ListBox, I would like the focus to be on the newly added item, just like an edit box, always bring up the text box so that I can see new data is pouring in :)

Some guys told me that in 32-bit environment, the listbox has no memory limitations as long as your RAM can provide u.  There will be a 64K size limitation for 16-bit ones.
0
 
nietodCommented:
There are three ways (maybe more) to do this.  First of all you can select an item in two ways.  You can send the LB_SELECTSTRING message.  This searches for an item with a specified string and then selects it.  This is probably not the best way as the seach can be slow.  A better way might be to use the LB_SETCURSEL message.  This selectes the item at the specified index.  This should be faster and "more precise".  You can either keep a running count of the number of items in the list or you can use the LB_GETCOUNT message to get the number of items in the list.
0
 
nietodCommented:
Those are problaby the easeast ways. However there is a way that might look better, but be a little more complex.  You really don't want the item to be selected, you just want the  item to be visible.  With a little work you can have the item visible without it being selected.  (If you care)

You can send the LB_SETTOPINDEX to set the item that appears at the top of the list.  For example if 10 items can be visible at a time and there are 30 items in the list.  You want to set the top item to 20.  The only problem is figuring out the number of items that will be visible at a time.  You can do that using the list box's client area height and the height of an item.  you can get the height of an item using LB_GETITEMHEIGHT.

I hope this helps.
0
 
jtwine100697Commented:
  (Let us not use a shotgun to kill a fly...)

   Since you want to select the "just added" item, store the value that is returned from CListBox::AddString() function.  That will be the index of the new item, and then you can just call CListBox::SetCurSel(...) with the index of the newly added item:

      iIndex = m_lbListBox.AddString( sMyString );
      if( iIndex != LB_ERR )
         m_lbListBox.SetCurSel( iIndex );

   See?  Simple!  But note that if data is coming in fast enough, you might get a LOT of flicker.

-=- James.
0
 
nietodCommented:
That's basically what I suggested, except I forgot that LB_ADDSTRING returns an index.  However, if you don't actually want the item to be selected, but really just want it to be visible at the bottom of the box, then you have to do a little more work.
0
 
sllsglAuthor Commented:
I must say thanks to both nietod & james, u are a great help :)
I did experience alot of flickering & a delay in showing of data items since the PC is only a 486 (72MB RAM) with a weak VGA 1MB.
I appreciate what both of u have contributed.  

This is my final question - Will the SetCurSel() visually "select" the whole newly added item or will it just set the focus to the newly added item by just making it visible in the ListBox?
0
 
jtwine100697Commented:
 I believe that it will make the item visible as well as select it.  It needs to be visible in order for the selection to be noticed.

-=- James.
0
 
sllsglAuthor Commented:
Hi, everyone, just wanna tell u all that there is a simpler way to make a ListBox Auto V-Scroll without selecting the item but just make the newly added item visible once it's added, no matter where how big your ListBox is.

The first part is the same, keep track of the index return after calling AddString().
Then call SetCaretIndex( THE_RETURN_INDEX, FALSE);

Just that, easy :)

Bye :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.