Search code examples
mfccedit

MFC CEdit character delete not working


I stumbled upon a strange problem today on one of my client's Windows XP SP 3: deleting with BACKSPACE or DELETE buttons a text from a CEdit won't work. To be more accurate, i place the cursor at the end of the text, and hitting the BACKSPACE button will result in moving the text cursor to the left, but deleted characters won't dissapear. The actual delete takes place, because if i force a refresh of the window, the deleted characters are missing. I guess is a paint issue, but i can't find what's wrong and how to work around it, and i couldn't reproduce the bug elsewhere. I checked the code, and the CEdits that behave like that have no events overriden, and no special properties set.


Solution

  • My answer is a guess: You overwrote WM_CTLCOLOREDIT and you are returning a NULL Brush to draw transparent.

    The result is what you see. Without the capability to overwrite the background the edit control shows artifacts...

    This "trick" of drawing transparent in Standard controls isn't a real good one but it is spread all over the Internet so that everybody uses it without knowing the drawbacks. Usually this works only for static controls that don't change.