Press a key in a MFC ActiveX control
-
I wrote a MFC ActiveX control with the Wizard. I want to do something when the user press a key and the control has the focus, so I wrote: void CMyControlCtrl::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) { // TODO: Add your message handler code here and/or call default AfxMessageBox("Key pressed") ; COleControl::OnChar(nChar, nRepCnt, nFlags); } Now if I insert the control in a Visual Basic Form it works right, but if I insert it in the dialog of a MFC Dialog based application it doesn't work. Can someone help me? Thanks Paolo
-
I wrote a MFC ActiveX control with the Wizard. I want to do something when the user press a key and the control has the focus, so I wrote: void CMyControlCtrl::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) { // TODO: Add your message handler code here and/or call default AfxMessageBox("Key pressed") ; COleControl::OnChar(nChar, nRepCnt, nFlags); } Now if I insert the control in a Visual Basic Form it works right, but if I insert it in the dialog of a MFC Dialog based application it doesn't work. Can someone help me? Thanks Paolo
I think that you need do some thing at the control PreTranslateAccelerator method function like following code. BOOL CInPlaceEdit::PreTranslateAccelerator(LPMSG pMsg, HRESULT& hRet) { if( ( pMsg->message == WM_KEYDOWN || pMsg->message == WM_KEYUP ) && ( pMsg->wParam == VK_LEFT || pMsg->wParam == VK_RIGHT || pMsg->wParam == VK_UP || pMsg->wParam == VK_DOWN || pMsg->wParam == VK_TAB) ) { hRet = S_FALSE; return TRUE; } return FALSE; } :cool: cz
-
I think that you need do some thing at the control PreTranslateAccelerator method function like following code. BOOL CInPlaceEdit::PreTranslateAccelerator(LPMSG pMsg, HRESULT& hRet) { if( ( pMsg->message == WM_KEYDOWN || pMsg->message == WM_KEYUP ) && ( pMsg->wParam == VK_LEFT || pMsg->wParam == VK_RIGHT || pMsg->wParam == VK_UP || pMsg->wParam == VK_DOWN || pMsg->wParam == VK_TAB) ) { hRet = S_FALSE; return TRUE; } return FALSE; } :cool: cz
Thanks for your answer, I'm not an expert on MFC and I didn't find any documentation on PreTranslateAccelerator and how to use it so I'm not so good to try your advice. I'm not sure that the problem is on Accelerator because in VB it works fine. To try my problem just create a new MFC ActiveX ControlWizard (in the second windows check the "Available in "Insert object" dialog") then add the Window message handler WM_CHAR like in my previous message. Now compile and register it. Try to insert in a VB form and in a Dialog based MFC program. Thanks in advance. Paolo
-
I think that you need do some thing at the control PreTranslateAccelerator method function like following code. BOOL CInPlaceEdit::PreTranslateAccelerator(LPMSG pMsg, HRESULT& hRet) { if( ( pMsg->message == WM_KEYDOWN || pMsg->message == WM_KEYUP ) && ( pMsg->wParam == VK_LEFT || pMsg->wParam == VK_RIGHT || pMsg->wParam == VK_UP || pMsg->wParam == VK_DOWN || pMsg->wParam == VK_TAB) ) { hRet = S_FALSE; return TRUE; } return FALSE; } :cool: cz
isn't it PreTranslateMessage() ? --- "every year we invent better idiot proof systems and every year they invent better idiots"
-
Thanks for your answer, I'm not an expert on MFC and I didn't find any documentation on PreTranslateAccelerator and how to use it so I'm not so good to try your advice. I'm not sure that the problem is on Accelerator because in VB it works fine. To try my problem just create a new MFC ActiveX ControlWizard (in the second windows check the "Available in "Insert object" dialog") then add the Window message handler WM_CHAR like in my previous message. Now compile and register it. Try to insert in a VB form and in a Dialog based MFC program. Thanks in advance. Paolo
-
Yes, PreTranslateAccelerator is for ATL control and you can use PreTranslateMessage method as the another person's suggest. Please read MSDN following article: PRB: MFC ActiveX Control Ignores ARROW Keys on VB Container Good Luck!
I read the article that you suggest me. But my problem isn't about the accelerator keys, I have the problem with each kind of keys. It seems that the control hasn't the focus (or something similar). If you read the article "MFC ActiveX Control in IE Doesn't Detect Keystrokes" (Q168777) they speak about the activation of the control within IE. I tried their suggestions but I didn't solve my problem. If you have time to check just create an MFC ActiveX control with the wizard (confirm all the default properties and set the "available in insert object dialog"), then add the function OnChar (WM_CHAR) and write inside it AfxMessageBox("Key pressed"). Now insert the object in a VB form and it works, but if you insert in a VC MFC dialog based application (with the wizard) it doesn't work. I'm using Visual Studio 6.0. Thanks Paolo. :confused: