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. Capturing 'Enter' key

Capturing 'Enter' key

Scheduled Pinned Locked Moved C / C++ / MFC
tutorial
5 Posts 4 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.
  • T Offline
    T Offline
    Toni78
    wrote on last edited by
    #1

    When I have a modeless dialog window opened and I hit enter the dialog will dissapear. I don't want that to happen. If I am editing the data in a control and I hit enter I would like the focus to shift as if I pressed tab. I got the following code from this website but I don't understand it. I can't find WM_GETDLGCODE and on top of that I don't want to create a new class just to capture a message. UINT SMUPPGrid::OnGetDlgCode() { UINT result = CListCtrl::OnGetDlgCode(); result = result | DLGC_WANTALLKEYS; return result; } Can someone tell me how to capture 'enter' and shift the focus from one control to another. none

    J 1 Reply Last reply
    0
    • T Toni78

      When I have a modeless dialog window opened and I hit enter the dialog will dissapear. I don't want that to happen. If I am editing the data in a control and I hit enter I would like the focus to shift as if I pressed tab. I got the following code from this website but I don't understand it. I can't find WM_GETDLGCODE and on top of that I don't want to create a new class just to capture a message. UINT SMUPPGrid::OnGetDlgCode() { UINT result = CListCtrl::OnGetDlgCode(); result = result | DLGC_WANTALLKEYS; return result; } Can someone tell me how to capture 'enter' and shift the focus from one control to another. none

      J Offline
      J Offline
      Joaquin M Lopez Munoz
      wrote on last edited by
      #2

      Try overriding OnOK. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

      T 1 Reply Last reply
      0
      • J Joaquin M Lopez Munoz

        Try overriding OnOK. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

        T Offline
        T Offline
        Toni78
        wrote on last edited by
        #3

        I don't have an IDC_OK handle to deal with. I have removed that button. How can I override the function when I don't have a handle for it? none

        K R 2 Replies Last reply
        0
        • T Toni78

          I don't have an IDC_OK handle to deal with. I have removed that button. How can I override the function when I don't have a handle for it? none

          K Offline
          K Offline
          karl_w
          wrote on last edited by
          #4

          Just add a new function called OnOK() in your dialog-class. And be sure not to call CDialog::OnOK() -- karl

          1 Reply Last reply
          0
          • T Toni78

            I don't have an IDC_OK handle to deal with. I have removed that button. How can I override the function when I don't have a handle for it? none

            R Offline
            R Offline
            Roger Allen
            wrote on last edited by
            #5

            You can modify how the enter key works by overriding the virtual function PreTranslateMessage()

            if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN)
            pMsg->wParam = VK_TAB;

            this will cause all ENTER keys to be treated as TABs Roger Allen Sonork 100.10016 Were you different as a kid? Did you ever say "Ooohhh, shiny red" even once? - Paul Watson 11-February-2003

            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