hi i put a listctrl in a framewnd ,i wanna do some works when the user press return key when a list item is selected ,i tried NM_RETURN event but it doesn't work ,some one can help me??
Printable View
hi i put a listctrl in a framewnd ,i wanna do some works when the user press return key when a list item is selected ,i tried NM_RETURN event but it doesn't work ,some one can help me??
Override CListCtrl with CYourListCtrl and override PreTransLateMessage with something like that:
Code:BOOL CYourListCtrl::PreTranslateMessage(MSG* pMsg)
{
if( pMsg->message == WM_KEYDOWN )
{
if(pMsg->wParam == VK_RETURN)
{
::TranslateMessage(pMsg);
::DispatchMessage(pMsg);
return TRUE; // DO NOT process further
}
}
return CListCtrl::PreTranslateMessage(pMsg);
}
Ah, Reorx, that's a little 'brute force' for me :
Try this :
I prefer not to use PreTranslateMessage otherwise you'll end up with everything in it if you're not careful.Code:// in.cpp
BEGIN_MESSAGE_MAP(CMyInheritedListCtrl, CListCtrl)
ON_WM_KEYDOWN()
END_MESSAGE_MAP()
// in .h
afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
// in .cpp
void CMyInheritedListCtrl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
CListCtrl::OnKeyDown(nChar, nRepCnt, nFlags);
if (nChar == VK_RETURN)
{
// yep it's trapped - do whatever you want
}
}
Darwen.
thanks to all for ur replay ,
the solution that ReorX gives works perfectly!!
It is not the solution Microsoft programmers and MFC experts use.Quote:
Originally posted by Black_Daimond
the solution that ReorX gives works perfectly!!
Most people that understand the solutions used by experts choose not to use PreTranslateMessage.Quote:
Originally posted by ReorX
Override CListCtrl with CYourListCtrl and override PreTransLateMessage with something like