I've got a problem with displaying modal dialog after key pressing. I'm doing it in thath way: first any key pressing is receiving in PreTranslateMessage function. Then i'm sending new user message which i'm handling in function "OnFunctionKeyPressed" that recognizing specific key. And in the end - after pressing i.e. F7 key - i want to display modal dialog. After DoModal - i'm receiving following error stack:
Error in assertionCode:> SPR System.exe!CWnd::AssertValid() Line 896 + 0x24 bytes C++ SPR System.exe!AfxAssertValidObject(const CObject * pOb=0x025d48a8, const char * lpszFileName=0x0080c570, int nLine=2433) Line 107 C++ SPR System.exe!CWnd::GetTopLevelParent() Line 2435 C++ SPR System.exe!AfxInternalPreTranslateMessage(tagMSG * pMsg=0x002fe7f0) Line 241 + 0x8 bytes C++ SPR System.exe!CWinThread::PreTranslateMessage(tagMSG * pMsg=0x002fe7f0) Line 777 + 0x9 bytes C++ SPR System.exe!CSystemRTApp::PreTranslateMessage(tagMSG * pMsg=0x002fe7f0) Line 1132 C++ SPR System.exe!AfxPreTranslateMessage(tagMSG * pMsg=0x002fe7f0) Line 252 + 0x11 bytes C++ SPR System.exe!AfxInternalPumpMessage() Line 178 + 0x18 bytes C++ SPR System.exe!CWinThread::PumpMessage() Line 900 C++ SPR System.exe!AfxPumpMessage() Line 190 + 0xd bytes C++ SPR System.exe!CWnd::RunModalLoop(unsigned long dwFlags=4) Line 4386 + 0x5 bytes C++ SPR System.exe!CDialog::DoModal() Line 584 + 0xc bytes C++function with key handling:Code:ASSERT(::IsWindow(m_hWnd));
next function:Code:BOOL CDialogDMMenu::PreTranslateMessage(MSG* pMsg) { if ( pMsg->message == WM_KEYDOWN ) { ::SendMessage( GetSafeHwnd(), WM_DMMENUKEYPRESSED, pMsg->wParam, 0 ); } return CDialog::PreTranslateMessage(pMsg); }
and ...Code:afx_msg LRESULT CDialogDMMenu::OnFunctionKeyPressed(WPARAM wParam, LPARAM lParam ) { BYTE key = 0x00; switch ( wParam ) { case VK_F1 : key=0x01; break; case VK_F2 : key=0x02; break; case VK_F3 : key=0x03; break; case VK_F4 : key=0x04; break; case VK_F5 : key=0x05; break; case VK_F6 : key=0x06; break; case VK_F7 : key=0x07; break; case VK_F8 : key=0x08; break; case VK_F9 : key=0x09; break; case VK_F10 : key=0x10; break; case VK_F11 : key=0x11; break; case VK_F12 : key=0x12; break; case VK_ESCAPE : OnCancel(); break; default : break; } functionKeyPressed(key); return 0; }
Where is error? Is there any other way to handle key pressing in application... Thank you. Regards...Code:void CDialogDMMenu::functionKeyPressed(BYTE key) { CDialogNewValue newValDialog(key); if ( newValDialog.DoModal() == IDOK ) { val = newValDialog.m_fValue; CRealtime::getInstance()->getReader()->setCommand( command, val ); } }




Reply With Quote