Lost Focus and GotFocus in C ++

How do you add code to these events for native C ++?

I could not find WM_LOSTFOCUS OR WM_GOTFOCUS ; I found WM_SETFOCUS . I need code when my window loses focus and restores it.

Thanks.

+4
source share
4 answers

ONLY BEFORE your window loses focus, it will be sent: WM_KILLFOCUS
AFTER your window receives focus, it will be sent: WM_SETFOCUS

Sending a WM_SETFOCUS message does not set focus. To do this, you need to call SetFocus.

+10
source

For the edit control, WM_KILLFOCUS will not work.

I thought for too long that I need EN_KILLFOCUS . Hope someone saves the next guy.

+3
source

The message you are looking for is WM_KILLFOCUS

+2
source

You may consider WM_ACTIVATE . In the main window, an activation message may be the only solution.

0
source