原文链接: http://computer-programming-forum.com/81-vc/c92ab6e6d6ac92bc.htm

楼主

How to handle the return key on a ClistCtrl ? I've tried to intercept 
the LVN_KEYDOWN message but the Return key is not handled !!! I've also 
tried to intercept the NM_RETURN message but it doesn't work 
Thanks in advance. 
O.Ferrandiz 

2楼

You need to override PreTranslateMessage to trap the WM_KEYDOWN(VK_RETURN) 
message like so: 

BOOL 
CListCtrlEx::PreTranslateMessage(MSG* pMsg) 

  if (((GetStyle() & LVS_EDITLABELS) == 0) || (pMsg->message != WM_KEYDOWN) 
|| (pMsg->wParam != VK_RETURN)) 
    return CListCtrl::PreTranslateMessage(pMsg); 

  // Send the message on to the control 
  DispatchMessage(pMsg); 
  return TRUE; 

}

Note that you don't need to call TranslateMessage() if you only need the 
WM_KEYDOWN message, as that function only causes a WM_CHAR(VK_RETURN) 
message to be sent to your handler.  Now you'll get the WM_NOTIFY(NM_RETURN) 
messages. 

 

相关文章:

  • 2021-05-30
  • 2021-10-26
  • 2022-12-23
  • 2021-09-27
  • 2021-07-03
  • 2022-12-23
  • 2022-02-11
  • 2021-06-28
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-06-18
  • 2021-06-12
  • 2021-10-20
  • 2022-12-23
  • 2021-05-20
相关资源
相似解决方案