请看http://expert.csdn.net/Expert/topic/1365/1365481.xml?temp=.2842523
为什么连窗口都不能成功创建了?

解决方案 »

  1.   

    重载PreTranslateMessage函数,加入对WM_KEYDOWN消息的处理。
      

  2.   

    结合:
    BOOL CKeyDowDlg::PreTranslateMessage(MSG* pMsg) 
    {
    // TODO: Add your specialized code here and/or call the base class
    switch (pMsg->message)
    {
    case WM_KEYDOWN:
    switch (pMsg->wParam)
    {
    case VK_RIGHT :
    AfxMessageBox( "right" ) ;
    break ;
    case VK_RETURN:
    AfxMessageBox( "enter" ) ;
    break ;
    case VK_LEFT:
    AfxMessageBox( "left" ) ;
    break ;
    case VK_DOWN:
    AfxMessageBox( "down" ) ;
    break ;
    case VK_UP:
    AfxMessageBox( "up" ) ;
    break; 
    case VK_BACK:
    AfxMessageBox( "backspace" ) ;
    break ;
    case VK_HOME:
    AfxMessageBox( "home" ) ;
    break ;
    case VK_END:
    AfxMessageBox( "end" ) ;
    break ;
    case VK_INSERT:
    AfxMessageBox( "insert" ) ;
    break ;
    case VK_DELETE:
    AfxMessageBox( "delete" ) ;
    break ;
    case VK_SCROLL:
    AfxMessageBox( "scrool" ) ;
    break; 
    case VK_PRINT:
    AfxMessageBox( "printf screen" ) ;
    break; 
    case VK_PAUSE:
    AfxMessageBox( "pause" ) ;
    break; 
    case VK_F1:
    AfxMessageBox( "f1" ) ;
    break;
    }
    case WM_KEYUP:
    break;
    case WM_CHAR:
    switch( pMsg->wParam )
    {
    case 65:
    AfxMessageBox( "A" ) ;
    break; 
    }
    default:
    break;
    }

    return CDialog::PreTranslateMessage(pMsg);
    }
      

  3.   

    再结合:
    十六进制     十进制 
    VK_NUMPAD0 60            96             Numeric keypad 0 key  
    VK_NUMPAD1 61            97             Numeric keypad 1 key  
    VK_NUMPAD2 62            98             Numeric keypad 2 key  
    VK_NUMPAD3 63            ..             Numeric keypad 3 key  
    VK_NUMPAD4 64            ..             Numeric keypad 4 key  
    VK_NUMPAD5 65            ..             Numeric keypad 5 key  
    VK_NUMPAD6 66            ..             Numeric keypad 6 key  
    VK_NUMPAD7 67            ..             Numeric keypad 7 key  
    VK_NUMPAD8 68            ..             Numeric keypad 8 key  
    VK_NUMPAD9 69            ..             Numeric keypad 9 key  
    VK_MULTIPLY  6A          106            Multiply key  
    VK_ADD       6B          107            Add key  
    VK_SEPARATOR 6C          108            Separator key  
    VK_SUBTRACT  6D          109            Subtract key  
    VK_BACK      08          08             BACKSPACE key  
      

  4.   

    还是不行啊:(一运行就提示错误要关闭窗口。
    会不会是构造函数出的问题?我把CCalcDig类的定义(在calcDig.h中)贴上,请看看:
    class CCalcDlg : public CDialog
    {
    // Construction
    public:public:
    int m_fun; //m_fun是运算符如:+,-,*,/
    void AddFun(int j); //输入一个运算符
    void AddNum(int i); //输入一个数字
    int m_ForS; //指示此时输入的是
    //第一个数还是第二个数
    bool m_firx,m_secx; //指示此时是否在输入小数部分
    //即是否按过了小数点
    double m_first,m_second; //第一第二个数
    double m_firstz,m_secondz; //第一第二个数的整数部分
    double m_firstx,m_secondx; //第一第二个数的小数部分

    int m_firxw,m_secxw; //第一第二个数的小数部分的位数
    int m_firzorf,m_seczorf; //指示是否是负数
    //既是否按过+/-键
    bool m_EnterSec; //是否输入了第二个数; double m_result; //结果
    double m_mfir,m_msec; // 记住上次参加运算的第一二个数
    bool m_sfmf,m_sfms,m_sfmfun; //指示是否此时还记的上次的数和运算符
    int m_mfun; //记住上次的运算符
        BOOL PreTranslateMessage(MSG* pMsg);//用来响应键盘事件
    CCalcDlg(CWnd* pParent = NULL); // standard constructor
    // Dialog Data
    //{{AFX_DATA(CCalcDlg)
    enum { IDD = IDD_CALC_DIALOG };
    // NOTE: the ClassWizard will add data members here
    CEdit m_xedit;
    double m_x;
    //}}AFX_DATA // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CCalcDlg)
    protected:
    virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
    //}}AFX_VIRTUAL// Implementation
    protected:
    HICON m_hIcon; // Generated message map functions
    //{{AFX_MSG(CCalcDlg)
    afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
    afx_msg void OnPaint();
    afx_msg HCURSOR OnQueryDragIcon();
    afx_msg void On0();
    afx_msg void On1();
    afx_msg void On2();
    afx_msg void On3();
    afx_msg void On4();
    afx_msg void On5();
    afx_msg void On6();
    afx_msg void On7();
    afx_msg void On8();
    afx_msg void On9();
    afx_msg void OnAdd();
    afx_msg void OnBack();
    afx_msg void OnDiv();
    afx_msg void OnGo();
    afx_msg void OnClean();
    afx_msg void OnSub();
    afx_msg void OnTim();
    afx_msg void OnXsd();
    afx_msg void OnZfh();
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    };