tags:

views:

1049

answers:

1

Is there any way to get the handle to the control that has focus? I am looking for a way to get the ID of control on focus in my app.

After that it would be easy to get the id with GetDlgCtrlID.

CWnd *pwnd = GetWindowOnFocus(); 
int wID = pwnd->GetDlgCtrlID();

It's the GetWindowOnFocus part that I am missing!

+4  A: 

Have a look at the static CWnd::GetFocus method.

Stu Mackellar
GetFocus is giving me back HWND - no idea about how to get control ID from HWND :-)
JohnIdol
You need to call the static CWnd::GetFocus method, which returns a CWnd*, not the Win32 ::GetFocus function, which returns an HWND.
Stu Mackellar
OK thanks - it works
JohnIdol