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. Best Approach to process KeyStrokes in Rich Edit

Best Approach to process KeyStrokes in Rich Edit

Scheduled Pinned Locked Moved C / C++ / MFC
c++help
4 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.
  • F Offline
    F Offline
    ForNow
    wrote on last edited by
    #1

    Hi, I am looking for the best approach to process KeyStroked My code is MFC using Message using message mapping macros I have a number of questions 1) what would the message be for a Keystrokes 2) is the message directed to the Dialog Box that contains the rich edit or is better to have the rich edit process to message 3) if I wrap the CDialog with a CWinThread I can use the ::Run command to process the key strokes

    int CWinthread::Run()
    { ASSERT_VALID(this);
    MSG m_msgCur;
    for tracking the idle time state
    if (!flags.is_connected)
    return TRUE;
    BOOL bIdle = TRUE;
    LONG lIdleCount = 0;
    // acquire and dispatch messages until a WM_QUIT message is received.
    for (;;)
    { phase1: // check to see if we can do idle work
    while (bIdle && !::PeekMessage(&m_msgCur, NULL, NULL, NULL, PM_NOREMOVE))
    { // call OnIdle while in bIdle state
    if (!OnIdle(lIdleCount++))
    bIdle = FALSE; // assume "no idle" state
    } // phase2: pump messages while available
    do { // pump message, but quit on WM_QUIT
    if (!PumpMessage())
    return ExitInstance();
    // reset "no idle" state after pumping "normal" message
    if (IsIdleMessage(&m_msgCur)) {
    bIdle = TRUE;
    lIdleCount = 0;}
    } while (::PeekMessage(&m_msgCur, NULL, NULL, NULL, PM_NOREMOVE));
    }
    ASSERT(FALSE); // not reachable
    }

    thanks for youe help

    _ 1 Reply Last reply
    0
    • F ForNow

      Hi, I am looking for the best approach to process KeyStroked My code is MFC using Message using message mapping macros I have a number of questions 1) what would the message be for a Keystrokes 2) is the message directed to the Dialog Box that contains the rich edit or is better to have the rich edit process to message 3) if I wrap the CDialog with a CWinThread I can use the ::Run command to process the key strokes

      int CWinthread::Run()
      { ASSERT_VALID(this);
      MSG m_msgCur;
      for tracking the idle time state
      if (!flags.is_connected)
      return TRUE;
      BOOL bIdle = TRUE;
      LONG lIdleCount = 0;
      // acquire and dispatch messages until a WM_QUIT message is received.
      for (;;)
      { phase1: // check to see if we can do idle work
      while (bIdle && !::PeekMessage(&m_msgCur, NULL, NULL, NULL, PM_NOREMOVE))
      { // call OnIdle while in bIdle state
      if (!OnIdle(lIdleCount++))
      bIdle = FALSE; // assume "no idle" state
      } // phase2: pump messages while available
      do { // pump message, but quit on WM_QUIT
      if (!PumpMessage())
      return ExitInstance();
      // reset "no idle" state after pumping "normal" message
      if (IsIdleMessage(&m_msgCur)) {
      bIdle = TRUE;
      lIdleCount = 0;}
      } while (::PeekMessage(&m_msgCur, NULL, NULL, NULL, PM_NOREMOVE));
      }
      ASSERT(FALSE); // not reachable
      }

      thanks for youe help

      _ Offline
      _ Offline
      _Superman_
      wrote on last edited by
      #2

      The messages for keystrokes are WM_KEYDOWN and WM_KEYUP. These are directed to the parent dialog containing the control. To have the message directed to the control in MFC, you have to create a class derived from CRichEditCtrl and then subclass the control from the InitDialog function of the dialog class using the SubclassDlgItem[^] method.

      «_Superman_»  _I love work. It gives me something to do between weekends.

      _Microsoft MVP (Visual C++)

      Polymorphism in C

      J F 2 Replies Last reply
      0
      • _ _Superman_

        The messages for keystrokes are WM_KEYDOWN and WM_KEYUP. These are directed to the parent dialog containing the control. To have the message directed to the control in MFC, you have to create a class derived from CRichEditCtrl and then subclass the control from the InitDialog function of the dialog class using the SubclassDlgItem[^] method.

        «_Superman_»  _I love work. It gives me something to do between weekends.

        _Microsoft MVP (Visual C++)

        Polymorphism in C

        J Offline
        J Offline
        JohnCz
        wrote on last edited by
        #3

        Superman: I respectfully disagree. quote: "The messages for keystrokes are WM_KEYDOWN and WM_KEYUP These are directed to the parent dialog containing the control." Unless dialog does not contain any controls, dialog window never gets focus, hence WN_KEYDOWN and WM_KEYUP messages are not sent to a dialog. quote: "and then subclass the control from the InitDialog function of the dialog class using the SubclassDlgItem method." It is possible to use SubclassDlgItem or SubclassWindow but it would be much easier to let the wizard do subclassing, by simply add variable of the CRichEditCtrl and later replace it with the derived class type. ForNow: Depending what is exactly you are trying to achieve, I think the best way to handle special keys is creating accelerators and add handlers to a CRichEditCtrl derived class.

        JohnCz

        1 Reply Last reply
        0
        • _ _Superman_

          The messages for keystrokes are WM_KEYDOWN and WM_KEYUP. These are directed to the parent dialog containing the control. To have the message directed to the control in MFC, you have to create a class derived from CRichEditCtrl and then subclass the control from the InitDialog function of the dialog class using the SubclassDlgItem[^] method.

          «_Superman_»  _I love work. It gives me something to do between weekends.

          _Microsoft MVP (Visual C++)

          Polymorphism in C

          F Offline
          F Offline
          ForNow
          wrote on last edited by
          #4

          how about using virtual ::PretranslateMessage

          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