在Dialog中有多个Button,按左右方向键,其默认行为是切换Button之间的焦点,
我想改变这种默认行为,需要在Dialog的KeyDown事件中响应左右方向键,如何才能实现?

解决方案 »

  1.   

    BOOL youdlg::PreTranslateMessage(MSG* pMsg) 
    {
    if (pMsg->message==WM_KEYDOWN && pMsg->wParam==VK_DOWN){ //按下向下键
    CWnd* wnd = FromHandle(pMsg->hwnd);
    ff2=true;
    int i = wnd->GetDlgCtrlID();
    switch (i){
    case IDC_BUTTON1:
    GetDlgItem(IDC_BUTTON2)->SetFocus()
    return true;

    case IDC_BUTTON2:
    GetDlgItem(IDC_BUTTON3)->SetFocus()
    return true;
    .....................
      

  2.   

    在该Dialog的PreTransferMessage()中截获按键消息。
      

  3.   

    button是很特殊的,不能直接使用PreTranslateMessage