阅读:2651回复:2
求助:自制软键盘,编辑框无法接收到字符
用evc4.0写了一个软键盘,在模拟器上测试,一切正常,可拿到arm2440上却出了问题:我的测试程序是基于单文档的,这个程序可以接收到按键消息,但无法传递到对话框里,所以编辑框也就受不到字符了。但是按退格键、确认键等这些键是可以的,不知道为什么。下面是我的软键盘主要部分源码,各位大虾帮我看看是什么原因。
BOOL CKeyboardDlg::PreTranslateMessage(MSG* pMsg) { // TODO: Add your specialized code here and/or call the base class HWND wnd = ::GetForegroundWindow(); if(IsWindow(wnd)) { //如果当前激活窗口不是本程序的窗口 if(wnd != this->m_hWnd) { //激活窗口发生了改变 if(m_hFocus != wnd) { if(IsWindow(m_hFocus)) { //释放本进程和gFocus线程的联系 // AttachThreadInput( // GetWindowThreadProcessId(m_hWnd,NULL), // GetWindowThreadProcessId(m_hFocus,NULL), // FALSE); m_hFocus = ::GetFocus(); } m_hFocus = wnd; //使本进程和激活窗口的进程联系起来,接收本进程的按键消息 // AttachThreadInput( // GetWindowThreadProcessId(m_hWnd,NULL), // GetWindowThreadProcessId(m_hFocus,NULL), // TRUE); } } } return CDialog::PreTranslateMessage(pMsg); } void CKeyboardDlg::ReleaseFocus() { //释放焦点 if(IsWindow(m_hFocus)) { HWND wnd = ::GetForegroundWindow(); if(IsWindow(wnd)) { if(wnd == m_hFocus) { return; } } //设置保存的焦点窗口处于激活状态 ::SetForegroundWindow(m_hFocus); ::SetFocus(m_hFocus); } } void CKeyboardDlg::SendKeyMessage(int vk_code) { ReleaseFocus(); if(vk_code >= 'A' && vk_code <= 'Z') { /* SHORT nTmp = GetAsyncKeyState(VK_CAPITAL); if(!(GetKeyState(VK_CAPITAL) && 0xFF)) if(nTmp < 0) { keybd_event(VK_CAPITAL,0,0,0); keybd_event(VK_CAPITAL,0,KEYEVENTF_KEYUP,0); } */ if(m_bPressKeyShift) keybd_event(VK_SHIFT, 0, 0, 0); if(!m_bCapsLK) vk_code += 32;//lowercase keybd_event(vk_code, 0, 0, 0); keybd_event(vk_code, 0, KEYEVENTF_KEYUP, 0); if(m_bPressKeyShift) { keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0); m_bPressKeyShift = FALSE; m_KeyShift.ChangeColor(WHITE_COLOR); GetDlgItem(IDC_KEY_SHIFT)->SetWindowText(_T("SHIFT")); } } else if(vk_code == VK_LPARENTHESIS || vk_code == VK_RPARENTHESIS) { keybd_event(VK_SHIFT , 0, 0, 0); keybd_event(vk_code, 0, 0, 0); keybd_event(vk_code, 0, KEYEVENTF_KEYUP, 0); keybd_event(VK_SHIFT , 0, KEYEVENTF_KEYUP, 0); } else if(vk_code == VK_SHIFT) { keybd_event(VK_SHIFT, 0, 0, 0); keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0); m_KeyShift.ChangeColor(PALEGREEN_COLOR); m_bPressKeyShift = TRUE; //m_KeyShift. } else if(vk_code == VK_CAPITAL) { keybd_event(vk_code, 0, 0, 0); SHORT ntmp = GetKeyState(VK_CAPITAL); //只能得到VK_CAPITAL 的触发状态,0为大写状态,1为小写状态 keybd_event(vk_code, 0, KEYEVENTF_KEYUP, 0); char text; CString strText; if(ntmp == 0) { m_bCapsLK = TRUE; for(int id = IDC_KEY_A; id <= IDC_KEY_Z; id++) { text = 'A' + (id - IDC_KEY_A); strText = text; GetDlgItem(id)->SetWindowText(strText); } } else if(ntmp == 1) { m_bCapsLK = FALSE; for(int id = IDC_KEY_A; id <= IDC_KEY_Z; id++) { text = 'A' + (id - IDC_KEY_A) + 32; strText = text; GetDlgItem(id)->SetWindowText(strText); } } } else//VK_BACK,,VK_COMMA,VK_PERIOD,VK_ESCAPE,VK_SEMICOLON,VK_SLASH,VK_SPACE,VK_RETURN { keybd_event(vk_code, 0, 0, 0); keybd_event(vk_code, 0, KEYEVENTF_KEYUP, 0); } ReleaseFocus(); } |
|
沙发#
发布于:2009-08-10 11:32
咋没人回答啊,痛苦中
|
|
板凳#
发布于:2009-09-04 16:37
你的弹出窗口为当前活动窗口,当然不会输出到其它窗口,解决的办法是在创建窗口时不要把本窗口设置成当前活跃窗口CreateWindow()里面有,你看下MSDN
|
|