想给对话框中的几个button添加快捷键,采用了&+字母的方法,可是不知道什么原因编译后快捷键用不了。请问怎么回事儿?该怎么解决呢?谢谢!

解决方案 »

  1.   

    采用了&+字母的方法
    --你是指 确定(&O)这种方法么?按ALT+O没有反应?
      

  2.   

    1.在 OnInitDialog 里
      ::RegisterHotKey(m_hWnd,0xa009,MOD_CONTROL,0x57);
      ::SetFocus(m_hWnd);2.添加消息
    BOOL CMyMFCDlg::PreTranslateMessage(MSG* pMsg)
    {
      if (pMsg->message==WM_HOTKEY && pMsg->wParam==0xa009)
      {
        AfxMessageBox("Hello, This is hot key :-)");
      }
            return CDialog::PreTranslateMessage(pMsg);
    }LRESULT CMyMFCDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
    {
      if(message == WM_CLOSE)
      {
        ::UnregisterHotKey(m_hWnd,0xa009);
      }
      return CDialog::WindowProc(message, wParam, lParam);
    }好了,现在运行程序,请按 Ctrl + w ,:-)
    在Dlg的头文件中加入:       HACCEL m_hAccel;在Dlg的构造函数中加载加速键:基于对话框的程序如何使用加速键?m_hAccel=::LoadAccelerators(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDR_ACCELERATOR1));//加速键ID重载PreTranslateMessage函数:BOOL CDlg::PreTranslateMessage(MSG* pMsg){       // TODO: Add your specialized code here and/or call the base class       if(m_hAccel!=NULL)              if(::TranslateAccelerator(m_hWnd,m_hAccel,pMsg))                     return TRUE;       return CDialog::PreTranslateMessage(pMsg);}
      

  3.   

    回happyparrot:  采用了&+字母的方法
      --你是指 确定(&O)这种方法么?按ALT+O没有反应?是的,我用了这种方法,打开那个对话框的时候就是没有反应。
      

  4.   

    没问题啊,就将按钮的Caption属性改为" 确定(&O) " 就行了.