我有一个mfc对话框,包含十几个按钮、单选按钮和只读编辑控件。
我想知道用户何时在该对话框中点击ctrl+v,而不管哪个控件具有焦点。
如果这是c,我可以设置KeyPreview属性,我的表单将在各个控件之前接收所有的击键-但是如何在mfc对话框中执行此操作?

最佳答案

JTeagle是对的。您应该覆盖PreTranslateMessage()

// Example
BOOL CDlgFoo::PreTranslateMessage( MSG* pMsg )
{
  // Add your specialized code here and/or call the base class
  if ( pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN )
  {
    int idCtrl= this->GetFocus()->GetDlgCtrlID();
    if ( idCtrl == IDC_MY_EDIT ) {
      // do something <--------------------
      return TRUE; // eat the message
    }
  }

  return CDialog::PreTranslateMessage( pMsg );
}

10-08 09:18