An MFC PopupEdit Control

The PopupEdit class is a simple CEdit-derived MFC class, that behaves very much like the edit control that appears when you edit an entry in a ListView control. It’s designed to be very easy to use, and I think you might
find it useful in your own applications.

Using the control is very simple: Call PopupEdit::Create() to create the control. After that, you call PopupEdit::Show() to make it visible. When you show it, you can specify the rectangle (in client coordinates of the parent window) where you want to display it, along with an initial text. Every time the control goes away, it resets its text back to “” (an empty string).

When the control is displayed, it will automatically grab focus and select the string in it. When the user presses the Enter key to accept the new text, the control will send a PE_TEXTIN message to the parent window, with a pointer to the text in the LPARAM of the message. That way, it’s very easy to grab the new text. After that, or if the user presses ESC or gives another control the focus, the PopupEdit control will hide itself.

One nice thing of the control is it’s ability to auto-resize itself to make the string fit, just like the ListView control  does. This is only done if the control has the PE_AUTOHEXPAND style.

Grab the file here:

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>