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

 

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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值