Solved

Edit Box Diplaying Problem

Posted on 1998-03-27
18
220 Views
Last Modified: 2008-02-01
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 :)
0
Comment
Question by:sllsgl
  • 10
  • 4
  • 4
18 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 1183875
You can use SetWindowText() to change the text stored in the edit control.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1183876
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
 
LVL 4

Expert Comment

by:jtwine100697
ID: 1183877
  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
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
LVL 22

Expert Comment

by:nietod
ID: 1183878
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
 

Author Comment

by:sllsgl
ID: 1183879
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
 
LVL 22

Expert Comment

by:nietod
ID: 1183880
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
 
LVL 22

Expert Comment

by:nietod
ID: 1183881
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
 
LVL 22

Expert Comment

by:nietod
ID: 1183882
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
 
LVL 4

Expert Comment

by:jtwine100697
ID: 1183883
  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
 

Author Comment

by:sllsgl
ID: 1183884
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
 
LVL 22

Accepted Solution

by:
nietod earned 20 total points
ID: 1183885
Answer coming.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1183886
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
 
LVL 22

Expert Comment

by:nietod
ID: 1183887
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
 
LVL 4

Expert Comment

by:jtwine100697
ID: 1183888
  (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
 
LVL 22

Expert Comment

by:nietod
ID: 1183889
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
 

Author Comment

by:sllsgl
ID: 1183890
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
 
LVL 4

Expert Comment

by:jtwine100697
ID: 1183891
 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
 

Author Comment

by:sllsgl
ID: 1183892
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

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

810 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