1
votes

I am programming in C++ using MFC Document/View architecture. I have been trying to achieve something similar to MFC CEdit lose focus handler. I processed the message EN_KILLFOCUS as the answer suggests.

Basically, I'm doing this: I have text drawn in the view. When the users clicks the area of the text in the view, I position and show the CEdit window on top of it so users are able to edit the text. When the edit loses focus, I get the CEdit text and save it in the document. Then invalidate the view.

However, I seem to only receive the EN_KILLFOCUS message when the view loses focus. I have to click somewhere else, e.g. a docking window, or the toolbar, to make the CEdit lose focus. I want it to happen when I click anywhere else on the view, outside the CEdit box.

I am creating the CEdit with WS_CHILD style. I tried WS_POPUP but still the same problem.

Any help would be appreciated.

1

1 Answers

1
votes

Create a CEdit derived class/control. And create an instance of this class in your View

Handle the EN_KILLFOCUS in the derived class. You will be able to handle this message once user clicks outside the edit control window.
Keep your editbox as WS_CHILD.

Set focus to view on view's mouse down, call SerFocus() on view's LButtonDown.