Problem mit GetFocus und dynamic_cast
-
Hallo!
Ich unterscheide anhand des Typs des Controls, das den Focus hat, ob z.B. Copy ausgeführt werden darf.
Hier ist die Funktion:
void CDoc::OnUpdateEditCopy(CCmdUI* pCmdUI) { // Element mit Focus holen CWnd* pWnd = m_pView->GetFocus(); if (pWnd) { // Jetzt rausfinden, was es ist: CEdit* pEdit = dynamic_cast<CEdit*>(pWnd); CComboBox* pCbx = dynamic_cast<CComboBox*>(pWnd); CListBox* pLst = dynamic_cast<CListBox*>(pWnd); CSortListCtrl* pLsc = dynamic_cast<CSortListCtrl*>(pWnd); // Hat was funktioniert? pCmdUI->Enable(pEdit || pCbx || pLst || pLsc); } else { // Wenn nichts den Focus hat, kann man nichts machen. pCmdUI->Enable(FALSE); } }
Nun ist folgendes Phänomen aufgetreten:
Habe ich eine Controlvariable für ein Edit, dann funktioniert es. Habe ich nur eine Wertvariable, funktioniert der dynamic_cast nicht.Gibt es noch eine andere Möglichkeit, oder muss ich doch für alle Edits Controlvariablen anlegen?