首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ Builder >

MFC 接受键盘输入,该怎么处理

2012-03-24 
MFC 接受键盘输入 - C++ Builder / Windows SDK/API各位鸟,大家好,请问大家一下,如何在 MFC 中, 接收键盘

MFC 接受键盘输入 - C++ Builder / Windows SDK/API
各位鸟,大家好,请问大家一下,如何在 MFC 中, 接收键盘输入的字符?本人在先恭候。

[解决办法]

C/C++ code
public:      virtual BOOL PreTranslateMessage(MSG* pMsg);//-------------------------BOOL CTestKeyboardDlg::PreTranslateMessage(MSG* pMsg) {    m_keys.PreTranslateKey();    CString str;    if(m_keys.GetKeyAllState(str))    {        AfxMessageBox(str);    }    // TODO: Add your specialized code here and/or call the base class        return CDialog::PreTranslateMessage(pMsg);}
[解决办法]
C/C++ code
上面的代码加上KeyManage m_keys;//KeyManage类部分// KeyManage.h: interface for the KeyManage class.////////////////////////////////////////////////////////////////////////#if !defined(AFX_KEYMANAGE_H__0ED0B8CE_1D30_4E77_BCD3_C247AFAB9B2A__INCLUDED_)#define AFX_KEYMANAGE_H__0ED0B8CE_1D30_4E77_BCD3_C247AFAB9B2A__INCLUDED_#if _MSC_VER > 1000#pragma once#endif // _MSC_VER > 1000class KeyManage  {public:    BOOL GetKeyAllState(CString &str);    int GetKeyState(UINT vKey);    void PreTranslateKey();    KeyManage();    virtual ~KeyManage();    BYTE m_key[256];};#endif // !defined(AFX_KEYMANAGE_H__0ED0B8CE_1D30_4E77_BCD3_C247AFAB9B2A__INCLUDED_)#include "stdafx.h"#include "KeyManage.h"#ifdef _DEBUG#undef THIS_FILEstatic char THIS_FILE[]=__FILE__;#define new DEBUG_NEW#endif//////////////////////////////////////////////////////////////////////// Construction/Destruction//////////////////////////////////////////////////////////////////////KeyManage::KeyManage(){    memset(m_key,0,sizeof(BYTE)*256);}KeyManage::~KeyManage(){}void KeyManage::PreTranslateKey(){    GetKeyboardState(m_key);}inline int KeyManage::GetKeyState(UINT vKey){    ASSERT(vKey<256);    return m_key[vKey]&0x80;}BOOL KeyManage::GetKeyAllState(CString &str){    BOOL bPress = FALSE;    str = "";    for(int i=0;i<256;i++)    {        if(GetKeyState(i))        {            if(!bPress)            {                bPress = true;            }            char c = MapVirtualKey(i,2);            str += c;        }    }    return bPress;}
[解决办法]

家里网络 太差了
贴了几次都不成功

热点排行