获取全选(ctrl-a)以在CEdit控件上工作
问题描述:
我正在尝试在CEdit控件中实现全选(通过ctrl-a).我这样做是通过创建一个继承CEdit的类并为WM_KEYDOWN添加一个处理程序,如下所示:
I am trying to implement select all(via ctrl-a) in a CEdit control. I'm doing this by making a class which inherits CEdit and adding a handler for WM_KEYDOWN like this:
void CEditExtended::OnKeyDown( UINT nChar, UINT nRepCnt, UINT nFlags )
{
if((nChar == 0x41) && (GetKeyState(VK_CONTROL) & 0x8000) != 0))
SetSel(0, -1);
CEdit::OnKeyDown(nChar, nRepCnt, nFlags);
}
这可以在网上四处浏览,但是它永远不会同时注册ctrl和a,两者都不能注册.
Looking around on the web, this should work, but it never registers both ctrl and a at the same time, either one or the other.
答
尝试以下代码:
void CEditExtended::PreTranslateMessage(MSG* pMsg)
{
if(pMsg->message == WM_KEYUP )
{
if ( (LOWORD(pMsg->wParam) & VK_CONTROL) == VK_CONTROL )
{
/// blah
}
}
return CEdit::PreTranslateMessage(pMsg);
}