Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Press a key in a MFC ActiveX control

Press a key in a MFC ActiveX control

Scheduled Pinned Locked Moved C / C++ / MFC
c++comhelpquestion
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    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

    C 1 Reply Last reply
    0
    • L Lost User

      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

      C Offline
      C Offline
      chenzhu
      wrote on last edited by
      #2

      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

      L L 2 Replies Last reply
      0
      • C chenzhu

        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

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        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

        C 1 Reply Last reply
        0
        • C chenzhu

          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

          L Offline
          L Offline
          l a u r e n
          wrote on last edited by
          #4

          isn't it PreTranslateMessage() ? --- "every year we invent better idiot proof systems and every year they invent better idiots"

          1 Reply Last reply
          0
          • L Lost User

            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

            C Offline
            C Offline
            chenzhu
            wrote on last edited by
            #5

            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!

            L 1 Reply Last reply
            0
            • C chenzhu

              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!

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              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:

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups