I guess you found out the function
SetFocus
:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646312%28v=vs.85%29.aspx[
^].
If you did, I don't know how could you miss
GetFocus
referenced from that page:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646294%28v=vs.85%29.aspx[
^].
The focus means keyboard focus; and only one control at a time in the whole system can have the focus. So, you find out
HWND
of the window which currently has focus and compare with
HWND
of the control you are interested in. If they are the same, your control is currently focused.
[EDIT]
DrBones69 asked:
I know how to set the focus to an edit control, but is there a way to check if an edit control has focus?
This would be another way. One can get
CWnd::GetFocus
, but still compare HWND of the result with HWND of the control in question. Please see:
http://msdn.microsoft.com/en-US/library/f9fd0z3x%28v=vs.100%29.aspx[
^],
http://msdn.microsoft.com/en-us/library/bcs64shx.aspx[
^].
In more general case, it's good to use
CWnd::GetSafeHwnd
, but the result
CWnd::GetFocus
will already return
NULL
in case of none is focused, and this result should be tested for
NULL
. Anyway, see also:
http://msdn.microsoft.com/en-us/library/d64ehwhz.aspx[
^].
—SA