Edit Control stops working when it is full

Bryan Kelly 516 Reputation points
2025-07-05T00:25:59.13+00:00

Windows 11, Visual Studio 2022, C++, MFC

I have been having great difficulties getting the basics working.

I was directed here from another Microsoft forum. When posting the question the drop downs for tag, child tag, and child item tag, have nothing that looks like a programming question for Visual Studio.  Am I in the wrong place?  If so, please redirect me.

Basic Problem

The code can write to the Edit Controls.  It cannot clear them.  The debugger indicates that the lower level calls are are defective, even though they work when the Edit Control is not full.  I suspect my declarations have a defect that but my knowledge is insufficient.

Details

This app does some 512 bit arithmetic using an array of uint64_t.  It displays the numbers, in hex, in Edit controls.  Below is the lowest level of my code that does the hex display. lp_cedit points to the edit control. lp_binary points to an array of ints, uint64_t.

lp_cedit->Clear(); // first two images are for this line and stepping in.

      ``for( int i = 0; i < U64_COUNT; i++) ``      ``{

        ``lp_binary->u64t[i] = input->u64t[i]; // copy the number to the lp_binary

        ``hex_string.Format(_T("%016llX "), lp_binary->u64t[i]); // Format each 64-bit word as hex

        ``lp_cedit->SetSel(-1, -1); // Move the cursor to the end of the edit control

        ``lp_cedit->ReplaceSel(hex_string); // second two images for this line.

      ``} 

The very first time the code attempts to display anything, in the debugger, at the Clear function, the Autos panel shows:

clear1

Step into the Clear function to see

clear2

The Autos display looks bad, but it does not assert.  Visual Studio makes no sound. 

Step out and down to the first call to ReplaceSel to see

replace1

Looks OK to me.  Step in to find the below

This looks bad. BUT it writes to the edit control.  Until the Edit Control is full of text.  They are set to no scroll.  Then the Clear() does nothing, does not assert, and the ReplaceSel() does nothing but it does assert.

The two critical pointers are declared and set as shown below

CEdit``       ``*lp_cedit = nullptr;``     

td_512_uint *lp_binary = nullptr;

 and used further down successfully

p_cedit = &m_edit_input_a;

p_select_binary = &m_512_input_a;

The ReplaceSel() works until the Edit Control is full.  The Clear() function appears to never work but never asserts.  It seems obvious to me that I have a setup wrong. 

I am hoping someone with more experience can recognize the problem.

Windows for home | Windows 11 | Display and graphics
{count} votes

Accepted answer
  1. Yve-cg 90 Reputation points
    2025-07-05T06:44:22.28+00:00

    Hi Bryan,

    Since I haven't heard back from you yet, I want to give you some practical steps you can try based on what you've shared so far. Hopefully, these help you move forward with your Edit Control issue:

    1. Try this to clear the text. Instead of using Clear(), try this line: lp_cedit->SetWindowText(_T(""));
      It's more reliable, even when the control is full.
    2. Remove the text limit. If the control is full, it may not let you add or remove anything. Try this: lp_cedit->SetLimitText(0); // 0 means "no limit"
    3. Is it single-line or multi-line?
      Single-line controls have more limits and no scrolling. If you're showing a lot of text, switch to multi-line and turn on scrollbars.
    4. Make sure it's not read-only. If the control is read-only, it won't let you change anything. To make sure it's editable: lp_cedit->SetReadOnly(FALSE);
    5. Double-check your pointer. Make sure lp_cedit always point to the right control and isn't null.

    If none of these work, we can look deeper at how the control is set up or how the data is handled. Try them out and let me know what happens. I'm here to help you figure it out.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.