我要在我的程序启动后,当键盘输入为字母或者数字时就弹出一个对话框,而且只有当我程序是激活状态时响应,不像有的热键,程序在后台也能响应。我只想做成上面这样简单。有无这样的例子(VC++)

解决方案 »

  1.   

    BOOL CChatTemplet::PreTranslateMessage(MSG* pMsg) 
    {
        if(GetForegroundWindow()==::FindWindow(NULL,"窗口名字"))//判断焦点在不在框内
        {
           if(pMsg->message==WM_KEYDOWN)
           {
       if(pMsg->wParam==VK_F1)
       {
    //         MessageBox("OK");
       }
           }
        }
        return CDialog::PreTranslateMessage(pMsg);
    }
      

  2.   

    这个就更简单了,直接用PreTranslateMessage()
    捕获所有的按键就行了.BOOL CMydilog::PreTranslateMessage(MSG* pMsg) 
    {
        if (pMsg->message == WM_KEYDOWN)
       {
            MessageBox("这里加入你弹出对话框的代码");
      }..
      

  3.   

    对于楼主的要求,这样的程序如果没有焦点时,该代码是不会响应的,
    所以不用判断程序的焦点问题.也就是说,
    BOOL CMydilog::PreTranslateMessage(MSG* pMsg) 
    {
        if (pMsg->message == WM_KEYDOWN)
       {
            MessageBox("这里加入你弹出对话框的代码");
      
        }
        return CDialog::PreTranslateMessage(pMsg);
    }
    只有当有焦点时才会响应,没有焦点是不会响应的
      

  4.   

    RegisterHotKey(m_hWnd,0Xa002,MOD_ALT,'A');
    ::SetFocus(m_hWnd);
    ************************************************************
    BOOL CDlg::PreTranslateMessage(MSG* pMsg) 
    {
    // TODO: Add your specialized code here and/or call the base class
    if (pMsg->message==WM_HOTKEY && pMsg->wParam==0Xa002)
    {
    AfxMessageBox("My MessageBox!");
    }
    return CDialog::PreTranslateMessage(pMsg);
    }LRESULT CDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
    {
    // TODO: Add your specialized code here and/or call the base class
    if(message == WM_CLOSE)
    {
    ::UnregisterHotKey(m_hWnd,0Xa002);
    }
    return CDialog::WindowProc(message, wParam, lParam);
    }
      

  5.   

    但是如果是一个多文档视图的程序呢?我这个PreTranslateMessage放在哪
      

  6.   

    如果是一个多文档视图的程序呢?我这个PreTranslateMessage放在哪A :可以自己在类向导的CMaimFrame里面添加PreTranslateMessage消息!
      

  7.   

    在CMaimFrame里添加PreTranslateMessage消息就可以了啊