CTreeView OnKeyDown beep
Posted: 14 Jun 2012, 23:07
De ceva timp incerc sa rezolv o problema : intr-un CTreeView daca se apasa tasta 'TAB' (sau inca cateva taste sistem (Enter, etc.), PC-ul scoate un beep :
Daca fac acelasi lucru intr-un view derivat din CListView, tasta 'TAB' merge fara sa scoata nici un sunet :
Cel mai bine se ilustreaza problema in proiectelul atasat ... care sa fie problema ? Daca tratez tasta 'TAB' in CTestTreeView::OnPreTranslateMessage(...) nu mai am acel beep ciudat, dar din cate stiu e de evitat sa se suprascrie OnPreTranslateMessage ... cazul asta sa fie o exceptie ?
Code: Select all
void CTestTreeView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
if(VK_TAB == nChar)
{
CChildFrame* pChild = (CChildFrame*)GetParentFrame();
CTestListView* pList = (CTestListView*)pChild->GetListView();
pList->SetFocus();
pList->GetListCtrl().SetItemState(0, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
}
CTreeView::OnKeyDown(nChar, nRepCnt, nFlags);
}
Code: Select all
void CTestListView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
if(VK_TAB == nChar)
{
CChildFrame* pChild = (CChildFrame*)GetParentFrame();
CTestListView* pTree = (CTestListView*)pChild->GetTreeView();
pTree->SetFocus();
}
CListView::OnKeyDown(nChar, nRepCnt, nFlags);
}