码迷,mamicode.com
首页 > 其他好文 > 详细

CListCtrl的LVN_KEYDOWN事件中怎么捕捉不到回车键?

时间:2015-07-31 14:35:26      阅读:202      评论:0      收藏:0      [点我收藏+]

标签:

 

原文链接: 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. 

 

CListCtrl的LVN_KEYDOWN事件中怎么捕捉不到回车键?

标签:

原文地址:http://www.cnblogs.com/huhu0013/p/4691958.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!