CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Mar 2003
    Location
    Morocco
    Posts
    257

    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

  2. #2
    Join Date
    Nov 2000
    Location
    Munich, Germany
    Posts
    161
    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.

  3. #3
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266

  4. #4
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940
    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.

  5. #5
    Join Date
    Mar 2003
    Location
    Morocco
    Posts
    257
    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

  6. #6
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266
    Originally posted by Black_Daimond
    the solution that ReorX gives works perfectly!!
    It is not the solution Microsoft programmers and MFC experts use.

  7. #7
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266
    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
  •  





Click Here to Expand Forum to Full Width

Featured