Solved

Edit Box Diplaying Problem

Posted on 1998-03-27
18
216 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
 
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

708 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