jmasterx
jmasterx

Reputation: 54193

Lost Focus and GotFocus in c++

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

I couldn't find a WM_LOSTFOCUS OR WM_GOTFOCUS; I only found WM_SETFOCUS. I need code to happen when my window loses focus, and regains it.

Thanks.

Upvotes: 6

Views: 9262

Answers (4)

Ben
Ben

Reputation: 57318

For an edit control, WM_KILLFOCUS won't work.

Took me too long to figure out that I needed EN_KILLFOCUS. Hopefully saves the next guy some time.

Upvotes: 3

Brian R. Bondy
Brian R. Bondy

Reputation: 347586

JUST BEFORE your window loses focus it will be sent: WM_KILLFOCUS
AFTER your window gains focus, it will be sent: WM_SETFOCUS

Sending a WM_SETFOCUS message does not set the focus. You need to call SetFocus for that.

Upvotes: 15

albert
albert

Reputation: 374

You may consider WM_ACTIVATE as well. When main window is concerned, activation message could be the only solution.

Upvotes: 0

BitBank
BitBank

Reputation: 8735

The message you're looking for is WM_KILLFOCUS

Upvotes: 2

Related Questions