-
November 25th, 2003, 05:50 AM
#1
return key pressed event from clistctrl
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??
We are the memories we let to other people
Rate if i helped
-
November 25th, 2003, 07:33 AM
#2
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);
}
The Saviour of the World is a Penguin and Linus Torvalds is his Prophet.
-
November 26th, 2003, 03:30 PM
#3
-
November 26th, 2003, 06:03 PM
#4
Ah, Reorx, that's a little 'brute force' for me :
Try this :
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
}
}
I prefer not to use PreTranslateMessage otherwise you'll end up with everything in it if you're not careful.
Darwen.
-
November 28th, 2003, 04:26 AM
#5
thanks to all for ur replay ,
the solution that ReorX gives works perfectly!!
We are the memories we let to other people
Rate if i helped
-
November 28th, 2003, 04:37 AM
#6
Originally posted by Black_Daimond
the solution that ReorX gives works perfectly!!
It is not the solution Microsoft programmers and MFC experts use.
-
November 28th, 2003, 04:39 AM
#7
Originally posted by ReorX
Override CListCtrl with CYourListCtrl and override PreTransLateMessage with something like
Most people that understand the solutions used by experts choose not to use PreTranslateMessage.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|