Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个 VC++ MFC 对话框应用程序,在我的 OnTimer 函数中,我只是想确定我的对话框中的哪个按钮当前具有焦点。
这是我想要完成的一些伪代码......
CDialog::OnTimer() { CButton *btn = GetButtonOnFocus(); int btnID = btn->GetDlgCtrlID(); }
我没有尝试过,但这应该有效:
CWnd * pFocus = GetFocus(); int btnID = 0; if (pFocus != NULL && pDialog->IsChild(pFocus)) btnID = pFocus->GetDlgCtrlID();
这不会将结果限制为仅按钮 - 为此,您需要使用 GetClassName 并与“按钮”进行比较。