Get button focus - MFC

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 pseudocode of what I am trying to accomplish.

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

      

0


a source to share


1 answer


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 does not limit the result to just buttons - you need to use GetClassName and compare to "button" for that.

+2


a source







All Articles