Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lost Focus and GotFocus in c++

Tags:

c++

native

winapi

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.

like image 605
jmasterx Avatar asked Sep 15 '09 00:09

jmasterx


3 Answers

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.

like image 98
Brian R. Bondy Avatar answered Oct 14 '22 01:10

Brian R. Bondy


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.

like image 3
Ben Avatar answered Oct 14 '22 01:10

Ben


The message you're looking for is WM_KILLFOCUS

like image 2
BitBank Avatar answered Oct 14 '22 01:10

BitBank