views:

388

answers:

1

Hi, I have a VC++ MFC dialog application and in my OnTimer function I am just trying to determine which button in my dialog currently has focus.

Here is some psuedocode of what I am trying to accomplish....

CDialog::OnTimer() { CButton *btn = GetButtonOnFocus(); int btnID = btn->GetDlgCtrlID(); }

Any help would be greatly apperciated.

Thanks

+1  A: 

I haven't tried it, but this should work:

CWnd * pFocus = GetFocus();
int btnID = 0;
if (pFocus != NULL && pDialog->IsChild(pFocus))
    btnID = pFocus->GetDlgCtrlID();

This won't restrict the result to buttons only - to do that, you need to use GetClassName and compare to "button".

Mark Ransom
Thanks, that was exactly what I was looking for. Thanks again1
JB_SO