Edit Control编辑框响应全选(Ctrl+A)

Edit Control编辑框响应全选(Ctrl+A)

[cpp]CEdit::SetSel(0, -1); //这是全选[/cpp]

具体思路是:

如果做它用,继承CEdit,响应WM_CHAR,收到A时判断Ctrl的状态

步骤一:

在头文件.h添加:

[cpp]afx_msg BOOL PreTranslateMessage(MSG* pMsg);[/cpp]

步骤二:

在源文件.cpp添加:

[cpp]

BOOL CmyDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if (pMsg->message==WM_KEYDOWN)
{
BOOL bCtrl=::GetKeyState(VK_CONTROL)&0x8000;
BOOL bShift=::GetKeyState(VK_SHIFT)&0x8000;

// only gets here if CTRL key is pressed
BOOL bAlt=::GetKeyState(VK_MENU)&0x8000;
switch( pMsg->wParam )
{
case ‘A’:
if (bCtrl)
m_cEdit.SetSel(0,-1);
break;
}
}
return CDialog::PreTranslateMessage(pMsg);
}

[/cpp]