问题描述
亲爱的所有人,
我正在使用MFC应用程序,此应用程序是使用VS2008编译的.
要捕获按下的键
OnKeyUp(UINT nChar,UINT nRepCnt,UINT nFlags)
使用方法.
发生的一件奇怪的事情是,当我按下不带大写锁定的键"a"时,其nChar值为"65",假设为"97".
即使大写锁定为"ON",当我按"A"时,我得到的值为"65".
问题是大写锁定处于打开状态或关闭状态,我得到的值与大写锁定处于打开状态相同. (所有键都是这种情况)
因为OnKeyUp()和MFC方法一样,所以我不确定如何解决此问题.
请帮助我,如果您需要更多信息,请通知我.
下面是我正在使用的代码,因此,发生这种情况是,当我使用SetDlgItemText()设置文本时,它总是以大写字母或单词的形式出现.
void CMyProg :: OnKeyUp(UINT nChar,UINT nRepCnt,UINT nFlags)
{
CString SBCommand;
CString Temp;
char * s = NULL;
char strnChar [10];
/*传递给命令框的字母和数字*/
if((nChar> = 65 && nChar< = 90)||(nChar> = 48 && nChar< = 57))
{
pFrame-> m_wndStatusBar.GetDlgItemText(IDC_SB_POINT,SBCommand);
Temp.Format(%c",nChar);
SBCommand + =温度;
pFrame-> m_wndStatusBar.SetDlgItemText(IDC_SB_POINT,SBCommand);
/*pFrame->m_wndStatusBar.GetDlgItemText(IDC_SB_POINT,SBCommand);
SBCommand + =(字符*)nChar;
pFrame-> m_wndStatusBar.SetDlgItemText(IDC_SB_POINT,SBCommand); */
}
}
Dear All,
I am working MFC Application, this application is compiled using VS2008.
To capture the key pressed
OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
method is used.
The strange thing happening is when i press the key "a" without caps lock its gives the nChar value as "65" which is suppose to be "97".
Even if the caps lock is "ON" the value i get is "65" when i press "A".
The thing is either the caps lock is on or off, i get the same value as if the caps lock is on. (this is the case with all the keys)
as the OnKeyUp() is as MFC method, I am not sure how to solve this issue.
Kindly help me and let me know if you require any more information.
Below is the code i am using, because of this what happens is, when i set a text using SetDlgItemText(), it is always going as Upper case letter or word.
void CMyProg::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
{
CString SBCommand;
CString Temp;
char *s = NULL;
char strnChar[10];
/* Alphabets and Numerals passed to the command box*/
if((nChar >= 65 && nChar <= 90) || (nChar >= 48 && nChar <= 57))
{
pFrame->m_wndStatusBar.GetDlgItemText(IDC_SB_POINT,SBCommand);
Temp.Format("%c",nChar);
SBCommand += Temp;
pFrame->m_wndStatusBar.SetDlgItemText(IDC_SB_POINT,SBCommand);
/*pFrame->m_wndStatusBar.GetDlgItemText(IDC_SB_POINT,SBCommand);
SBCommand += (char*)nChar;
pFrame->m_wndStatusBar.SetDlgItemText(IDC_SB_POINT,SBCommand);*/
}
}
推荐答案
这篇关于使用OnKeyUp(UINT nChar,UINT nRepCnt,UINT nFlags)方法进行键捕获的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!