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. EditBox & Enter

EditBox & Enter

Scheduled Pinned Locked Moved C / C++ / MFC
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.
  • I Offline
    I Offline
    IndrekSnt
    wrote on last edited by
    #1

    Hello, could it be possible to get a notification message when user presses Enter with the Editbox selected. If user hits Enter, it should get the editbox's text and write it into a Textbox.. All suggestions are welcome, Thank You..

    S 1 Reply Last reply
    0
    • I IndrekSnt

      Hello, could it be possible to get a notification message when user presses Enter with the Editbox selected. If user hits Enter, it should get the editbox's text and write it into a Textbox.. All suggestions are welcome, Thank You..

      S Offline
      S Offline
      Shay Harel
      wrote on last edited by
      #2

      CWnd* pWnd = GetFocus(); if(pWnd->GetDlgCtrlID() != IDOK) { if (pWnd->GetDlgCtrlID() == IDC_MYEDITBOX) //do something; } CDialog::OnOK();

      I 1 Reply Last reply
      0
      • S Shay Harel

        CWnd* pWnd = GetFocus(); if(pWnd->GetDlgCtrlID() != IDOK) { if (pWnd->GetDlgCtrlID() == IDC_MYEDITBOX) //do something; } CDialog::OnOK();

        I Offline
        I Offline
        IndrekSnt
        wrote on last edited by
        #3

        Thank You.. Seems that i posted it into a wrong discussion board.. :( Win32 API without MFC would be a bit more helpful for me as i'm using DevC++ and i don't know what equals to CDialog::OnOK(); All suggestions are welcome, Thank You..

        W 1 Reply Last reply
        0
        • I IndrekSnt

          Thank You.. Seems that i posted it into a wrong discussion board.. :( Win32 API without MFC would be a bit more helpful for me as i'm using DevC++ and i don't know what equals to CDialog::OnOK(); All suggestions are welcome, Thank You..

          W Offline
          W Offline
          willy_total
          wrote on last edited by
          #4

          here is Shay Harel code converted. case IDOK: HWND hWndChild = GetFocus(); if( hWndChild != GetDlgItem(hWnd, IDOK) ) { if( hWndChild == GetDlgItem(hWnd, IDC_MYEDITBOX) ) // do something; }

          I 1 Reply Last reply
          0
          • W willy_total

            here is Shay Harel code converted. case IDOK: HWND hWndChild = GetFocus(); if( hWndChild != GetDlgItem(hWnd, IDOK) ) { if( hWndChild == GetDlgItem(hWnd, IDC_MYEDITBOX) ) // do something; }

            I Offline
            I Offline
            IndrekSnt
            wrote on last edited by
            #5

            and with message WM_COMMAND and switch (LOWORD(wParam)) ? Why could if( hWndChild != GetDlgItem(hWnd, IDOK) ) be needed if the second one checks for a window in focus? With this switch i get a notification even if user clicks on the editbox. Is it possible to check HIWORD(wParam) for a mouseclick when the control is an editbox? Do i have to use ES_MULTILINE | ES_WANTRETURN flags when creating the editbox in order to make the control even receive a notification about Enter? Unfortunately i see no changes after adding these flags.. WinInf.EditBox = CreateWindow ("edit", "", WS_CHILD | WS_VISIBLE | ES_LEFT | ES_NOHIDESEL | ES_MULTILINE | ES_WANTRETURN, WinInf.ClientRect.left + 2, WinInf.ClientRect.bottom - 20, WinInf.ClientRect.right - 4, 20, hwnd, (HMENU) 1, WinInf.hInst, NULL); All suggestions are welcome, Thank You..

            W 1 Reply Last reply
            0
            • I IndrekSnt

              and with message WM_COMMAND and switch (LOWORD(wParam)) ? Why could if( hWndChild != GetDlgItem(hWnd, IDOK) ) be needed if the second one checks for a window in focus? With this switch i get a notification even if user clicks on the editbox. Is it possible to check HIWORD(wParam) for a mouseclick when the control is an editbox? Do i have to use ES_MULTILINE | ES_WANTRETURN flags when creating the editbox in order to make the control even receive a notification about Enter? Unfortunately i see no changes after adding these flags.. WinInf.EditBox = CreateWindow ("edit", "", WS_CHILD | WS_VISIBLE | ES_LEFT | ES_NOHIDESEL | ES_MULTILINE | ES_WANTRETURN, WinInf.ClientRect.left + 2, WinInf.ClientRect.bottom - 20, WinInf.ClientRect.right - 4, 20, hwnd, (HMENU) 1, WinInf.hInst, NULL); All suggestions are welcome, Thank You..

              W Offline
              W Offline
              willy_total
              wrote on last edited by
              #6

              You are making this much harder than it needs to be. This is a very easy thing to code. The following code does exactly what you need. All you have to do is copy it into your code and it will work. You don't need to mess around with the create options. The reason it works is because the IDOK button will be a default button, and will be called when the return is pressed. case WM_COMMAND: { switch(LOWORD(wParam)) { case IDOK: { HWND hWndChild = GetFocus(); if( hWndChild != GetDlgItem(hDlg, IDOK) ) { if( hWndChild == GetDlgItem(hDlg, IDC_EDIT1) ) { char szText[128]; GetWindowText(hWndChild, szText, sizeof(szText)); SetWindowText(GetDlgItem(hDlg, IDCS_TEXT), szText); return TRUE; } } EndDialog(hDlg, LOWORD(wParam)); } return TRUE;

              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