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. How to get datas from an edit control (in the toolbar) by pressing return (enter) ?

How to get datas from an edit control (in the toolbar) by pressing return (enter) ?

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

    Hi there:-D, i coded a small app. with an editbox in the toolbar. When the user makes an input(some numbers) in this editbox i want to store this number in a variable after the user has pressed return (enter) for further calculations. I'm tried this now for some houres without any success ;( :confused: Idont want to post to much or to small code snippets, so i coded a very small sample program (39 kb) only a toolbar and an editbox in it and the same problem :^) ! You can download it here: http://www.filehosting.at/files/download.php?file=f767c44c627cfdb696cb0cea5e24b8be You have to copy the link in your browser :confused: Only a click on it isn't enough :confused: Pleeese help me, it's really important for me! Thousand Thanx for yor help ! ;) best regards croc

    D M 2 Replies Last reply
    0
    • C CrocodileBuck

      Hi there:-D, i coded a small app. with an editbox in the toolbar. When the user makes an input(some numbers) in this editbox i want to store this number in a variable after the user has pressed return (enter) for further calculations. I'm tried this now for some houres without any success ;( :confused: Idont want to post to much or to small code snippets, so i coded a very small sample program (39 kb) only a toolbar and an editbox in it and the same problem :^) ! You can download it here: http://www.filehosting.at/files/download.php?file=f767c44c627cfdb696cb0cea5e24b8be You have to copy the link in your browser :confused: Only a click on it isn't enough :confused: Pleeese help me, it's really important for me! Thousand Thanx for yor help ! ;) best regards croc

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      CrocodileBuck wrote:

      ...without any success

      So what's the problem?

      "Love people and use things, not love things and use people." - Unknown

      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

      1 Reply Last reply
      0
      • C CrocodileBuck

        Hi there:-D, i coded a small app. with an editbox in the toolbar. When the user makes an input(some numbers) in this editbox i want to store this number in a variable after the user has pressed return (enter) for further calculations. I'm tried this now for some houres without any success ;( :confused: Idont want to post to much or to small code snippets, so i coded a very small sample program (39 kb) only a toolbar and an editbox in it and the same problem :^) ! You can download it here: http://www.filehosting.at/files/download.php?file=f767c44c627cfdb696cb0cea5e24b8be You have to copy the link in your browser :confused: Only a click on it isn't enough :confused: Pleeese help me, it's really important for me! Thousand Thanx for yor help ! ;) best regards croc

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #3

        You can subclass the edit control and look for the enter key press.  When the enter key is pressed you can post a message to another window to do the processing of the edit control contents. See method II here: How To Use the ENTER Key from Edit Controls in a Dialog Box[^] Also, a Google search on "enter key edit control" yields much info. Mark

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        C 1 Reply Last reply
        0
        • M Mark Salsbery

          You can subclass the edit control and look for the enter key press.  When the enter key is pressed you can post a message to another window to do the processing of the edit control contents. See method II here: How To Use the ENTER Key from Edit Controls in a Dialog Box[^] Also, a Google search on "enter key edit control" yields much info. Mark

          Mark Salsbery Microsoft MVP - Visual C++ :java:

          C Offline
          C Offline
          CrocodileBuck
          wrote on last edited by
          #4

          Thx for your quick reply ! The prob. ist that i don't know where i have to do what to get the datas after pressing return. And i haven't got a Dlg, the EditControl is on a Toolbar ! Thanx a lot best regards Croc

          modified on Monday, April 7, 2008 1:24 PM

          M C 2 Replies Last reply
          0
          • C CrocodileBuck

            Thx for your quick reply ! The prob. ist that i don't know where i have to do what to get the datas after pressing return. And i haven't got a Dlg, the EditControl is on a Toolbar ! Thanx a lot best regards Croc

            modified on Monday, April 7, 2008 1:24 PM

            M Offline
            M Offline
            Mark Salsbery
            wrote on last edited by
            #5

            Subclassing a control is the same for a window as it is for a dialog. You must have an HWND for the edit control if you put it there :) Subclassing Controls[^] If you're using MFC it's much simpler. Mark

            Mark Salsbery Microsoft MVP - Visual C++ :java:

            C 1 Reply Last reply
            0
            • C CrocodileBuck

              Thx for your quick reply ! The prob. ist that i don't know where i have to do what to get the datas after pressing return. And i haven't got a Dlg, the EditControl is on a Toolbar ! Thanx a lot best regards Croc

              modified on Monday, April 7, 2008 1:24 PM

              C Offline
              C Offline
              CrocodileBuck
              wrote on last edited by
              #6

              Ok, i'put this code in the newToolBar.cpp: BOOL New_cToolBar::PreTranslateMessage(MSG* pMsg) { if (pMsg->message==WM_KEYDOWN && pMsg->wParam == VK_RETURN ) { if (pMsg->message==WM_KEYDOWN && pMsg->wParam == VK_RETURN ) { if ( ID_nEDIT ) { MessageBox( _T("Got it!") ); } } } return New_cToolBar::PreTranslateMessage( pMsg ); } but int won't work ??? best regards Croc

              M 1 Reply Last reply
              0
              • M Mark Salsbery

                Subclassing a control is the same for a window as it is for a dialog. You must have an HWND for the edit control if you put it there :) Subclassing Controls[^] If you're using MFC it's much simpler. Mark

                Mark Salsbery Microsoft MVP - Visual C++ :java:

                C Offline
                C Offline
                CrocodileBuck
                wrote on last edited by
                #7

                Hi Mr.Salsbery, >>>If you're using MFC it's much simpler.<<<<br mode="hold" /> ...but i am usin g the glory MFC *heut* i tried it for more than 4 hours and i think i couldn't findd my mistake !!! best regards hopefullx Croc

                M 1 Reply Last reply
                0
                • C CrocodileBuck

                  Hi Mr.Salsbery, >>>If you're using MFC it's much simpler.<<<<br mode="hold" /> ...but i am usin g the glory MFC *heut* i tried it for more than 4 hours and i think i couldn't findd my mistake !!! best regards hopefullx Croc

                  M Offline
                  M Offline
                  Mark Salsbery
                  wrote on last edited by
                  #8

                  CrocodileBuck wrote:

                  i am usin g the glory MFC

                  In that case... Derive a class from CEdit Create the edit control using your derived class In the derived class, add a handler for WM_CHAR In the WM_CHAR handler, look for the enter key (as shown in the first link I posted)    If the enter key was pressed - do whatever you need to do    For all other keys, pass the message on to the edit control (call Default();)

                  Mark Salsbery Microsoft MVP - Visual C++ :java:

                  1 Reply Last reply
                  0
                  • C CrocodileBuck

                    Ok, i'put this code in the newToolBar.cpp: BOOL New_cToolBar::PreTranslateMessage(MSG* pMsg) { if (pMsg->message==WM_KEYDOWN && pMsg->wParam == VK_RETURN ) { if (pMsg->message==WM_KEYDOWN && pMsg->wParam == VK_RETURN ) { if ( ID_nEDIT ) { MessageBox( _T("Got it!") ); } } } return New_cToolBar::PreTranslateMessage( pMsg ); } but int won't work ??? best regards Croc

                    M Offline
                    M Offline
                    Mark Salsbery
                    wrote on last edited by
                    #9

                    That won't work because the message goes to the edit control, not to the toolbar :) Mark

                    Mark Salsbery Microsoft MVP - Visual C++ :java:

                    C 1 Reply Last reply
                    0
                    • M Mark Salsbery

                      That won't work because the message goes to the edit control, not to the toolbar :) Mark

                      Mark Salsbery Microsoft MVP - Visual C++ :java:

                      C Offline
                      C Offline
                      CrocodileBuck
                      wrote on last edited by
                      #10

                      Thx Mr. Salsbery, are there any CodeSnippets out there ? I think i couldn't manage it without ... :sigh: Best regards Croc

                      C M 2 Replies Last reply
                      0
                      • C CrocodileBuck

                        Thx Mr. Salsbery, are there any CodeSnippets out there ? I think i couldn't manage it without ... :sigh: Best regards Croc

                        C Offline
                        C Offline
                        CrocodileBuck
                        wrote on last edited by
                        #11

                        Perhaps you could have a look on my Code i posted !? Thx Best regards croc

                        1 Reply Last reply
                        0
                        • C CrocodileBuck

                          Thx Mr. Salsbery, are there any CodeSnippets out there ? I think i couldn't manage it without ... :sigh: Best regards Croc

                          M Offline
                          M Offline
                          Mark Salsbery
                          wrote on last edited by
                          #12

                          // MyEdit.h

                          #pragma once

                          class CMyEdit : public CEdit
                          {
                              DECLARE_DYNAMIC(CMyEdit)

                          public:
                              CMyEdit();
                              virtual ~CMyEdit();

                          protected:
                              DECLARE_MESSAGE_MAP()
                              afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
                          };

                          ////////////////////////////////////////////////////////////////////////

                          // MyEdit.cpp

                          #include "stdafx.h"
                          #include "MyEdit.h"

                          IMPLEMENT_DYNAMIC(CMyEdit, CEdit)

                          CMyEdit::CMyEdit() : CEdit()
                          {
                          }

                          CMyEdit::~CMyEdit()
                          {
                          }

                          BEGIN_MESSAGE_MAP(CMyEdit, CEdit)
                              ON_WM_CHAR()
                          END_MESSAGE_MAP()

                          void CMyEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
                          {
                              if (nChar == VK_RETURN)
                              {
                                  // do stuff!

                          return;
                              }

                          CEdit::OnChar(nChar, nRepCnt, nFlags);
                          }

                          Mark Salsbery Microsoft MVP - Visual C++ :java:

                          C 1 Reply Last reply
                          0
                          • M Mark Salsbery

                            // MyEdit.h

                            #pragma once

                            class CMyEdit : public CEdit
                            {
                                DECLARE_DYNAMIC(CMyEdit)

                            public:
                                CMyEdit();
                                virtual ~CMyEdit();

                            protected:
                                DECLARE_MESSAGE_MAP()
                                afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
                            };

                            ////////////////////////////////////////////////////////////////////////

                            // MyEdit.cpp

                            #include "stdafx.h"
                            #include "MyEdit.h"

                            IMPLEMENT_DYNAMIC(CMyEdit, CEdit)

                            CMyEdit::CMyEdit() : CEdit()
                            {
                            }

                            CMyEdit::~CMyEdit()
                            {
                            }

                            BEGIN_MESSAGE_MAP(CMyEdit, CEdit)
                                ON_WM_CHAR()
                            END_MESSAGE_MAP()

                            void CMyEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
                            {
                                if (nChar == VK_RETURN)
                                {
                                    // do stuff!

                            return;
                                }

                            CEdit::OnChar(nChar, nRepCnt, nFlags);
                            }

                            Mark Salsbery Microsoft MVP - Visual C++ :java:

                            C Offline
                            C Offline
                            CrocodileBuck
                            wrote on last edited by
                            #13

                            Many thx Mr. Salsbery, this will work, but only in a seperate project! Now i try to put your code in my code with the edit in the toolbar ! Where and how have i to implement it ???:confused: I never did anything in the MFC that was as complicated like this ! Many Thanx Croc

                            M 1 Reply Last reply
                            0
                            • C CrocodileBuck

                              Many thx Mr. Salsbery, this will work, but only in a seperate project! Now i try to put your code in my code with the edit in the toolbar ! Where and how have i to implement it ???:confused: I never did anything in the MFC that was as complicated like this ! Many Thanx Croc

                              M Offline
                              M Offline
                              Mark Salsbery
                              wrote on last edited by
                              #14

                              CrocodileBuck wrote:

                              this will work, but only in a seperate project!

                              You can't add another class to your project? :) How did you get the edit control on the toolbar (the code)?

                              Mark Salsbery Microsoft MVP - Visual C++ :java:

                              C 1 Reply Last reply
                              0
                              • M Mark Salsbery

                                CrocodileBuck wrote:

                                this will work, but only in a seperate project!

                                You can't add another class to your project? :) How did you get the edit control on the toolbar (the code)?

                                Mark Salsbery Microsoft MVP - Visual C++ :java:

                                C Offline
                                C Offline
                                CrocodileBuck
                                wrote on last edited by
                                #15

                                ??? Shur i can add classes but i'm ....:confused: ! I don't know where i have to implement your code and i don't know how to do it ! I tried it too long i think ! :( This is the declaration of the membervariable of my edit in NewToolBar.h : public: //************************************************************************************************************ CEdit m_Ctrl_EDIT; //************************************************************************************************************ In NewToolBar.cpp: BOOL NewToolBar::LoadToolBarEx(UINT id) { BOOL bReturn; bReturn = CToolBar::LoadToolBar(id); // Zugriff auf Elemente der Funktion LoadToolbar() int iPosition = CommandToIndex(ID_nEDIT); SetButtonInfo(iPosition,ID_nEDIT,TBBS_SEPARATOR,EDITLEN); CRect rect; GetItemRect(iPosition, rect); rect.bottom = 20; DWORD dwStyle = WS_CHILD|WS_VISIBLE|WS_TABSTOP|ES_AUTOHSCROLL;/*ES_NUMBER|*/ m_Ctrl_EDIT.CreateEx(WS_EX_CLIENTEDGE,_T("EDIT"),NULL, dwStyle, rect, this, ID_nEDIT); return bReturn; } i use the menber !!! i don't know how to implement code into mine, this is the prob ! Could you perhaps show it on my sample i posted, i know it's not the general way, im not to lazy, it simply won'work :( :( :( :sigh: :sigh: :sigh: :(( :(( :(( Thanx a lot Best regards Croc(master of desaster)

                                M 1 Reply Last reply
                                0
                                • C CrocodileBuck

                                  ??? Shur i can add classes but i'm ....:confused: ! I don't know where i have to implement your code and i don't know how to do it ! I tried it too long i think ! :( This is the declaration of the membervariable of my edit in NewToolBar.h : public: //************************************************************************************************************ CEdit m_Ctrl_EDIT; //************************************************************************************************************ In NewToolBar.cpp: BOOL NewToolBar::LoadToolBarEx(UINT id) { BOOL bReturn; bReturn = CToolBar::LoadToolBar(id); // Zugriff auf Elemente der Funktion LoadToolbar() int iPosition = CommandToIndex(ID_nEDIT); SetButtonInfo(iPosition,ID_nEDIT,TBBS_SEPARATOR,EDITLEN); CRect rect; GetItemRect(iPosition, rect); rect.bottom = 20; DWORD dwStyle = WS_CHILD|WS_VISIBLE|WS_TABSTOP|ES_AUTOHSCROLL;/*ES_NUMBER|*/ m_Ctrl_EDIT.CreateEx(WS_EX_CLIENTEDGE,_T("EDIT"),NULL, dwStyle, rect, this, ID_nEDIT); return bReturn; } i use the menber !!! i don't know how to implement code into mine, this is the prob ! Could you perhaps show it on my sample i posted, i know it's not the general way, im not to lazy, it simply won'work :( :( :( :sigh: :sigh: :sigh: :(( :(( :(( Thanx a lot Best regards Croc(master of desaster)

                                  M Offline
                                  M Offline
                                  Mark Salsbery
                                  wrote on last edited by
                                  #16

                                  CrocodileBuck wrote:

                                  CEdit m_Ctrl_EDIT;

                                  Change that line to CMyEdit m_Ctrl_EDIT; I gave you code that can be separated into a .h and a .cpp file. Do that, and add the files to your project.  :) Add the following line above the NewToolBar class decalration: #include "MyEdit.h" That's it!

                                  CrocodileBuck wrote:

                                  Could you perhaps show it on my sample i posted

                                  I could, but you wouldn't learn anything.  You should (IMO) be able to easily add classes to your projects. You'll be happier in the long run I bet :) Mark

                                  Mark Salsbery Microsoft MVP - Visual C++ :java:

                                  C 1 Reply Last reply
                                  0
                                  • M Mark Salsbery

                                    CrocodileBuck wrote:

                                    CEdit m_Ctrl_EDIT;

                                    Change that line to CMyEdit m_Ctrl_EDIT; I gave you code that can be separated into a .h and a .cpp file. Do that, and add the files to your project.  :) Add the following line above the NewToolBar class decalration: #include "MyEdit.h" That's it!

                                    CrocodileBuck wrote:

                                    Could you perhaps show it on my sample i posted

                                    I could, but you wouldn't learn anything.  You should (IMO) be able to easily add classes to your projects. You'll be happier in the long run I bet :) Mark

                                    Mark Salsbery Microsoft MVP - Visual C++ :java:

                                    C Offline
                                    C Offline
                                    CrocodileBuck
                                    wrote on last edited by
                                    #17

                                    Hi Mr.Salsbery, yap i'm sure you are right, the long way is better, and i'm able to add classes to my project :sigh: I added your code bur it still won't work ! :( http://www.filehosting.at/files/download.php?file=422e731948daac3a203df0de8c83b21b Thax a lot Best regards Croc :sigh:

                                    C 1 Reply Last reply
                                    0
                                    • C CrocodileBuck

                                      Hi Mr.Salsbery, yap i'm sure you are right, the long way is better, and i'm able to add classes to my project :sigh: I added your code bur it still won't work ! :( http://www.filehosting.at/files/download.php?file=422e731948daac3a203df0de8c83b21b Thax a lot Best regards Croc :sigh:

                                      C Offline
                                      C Offline
                                      CrocodileBuck
                                      wrote on last edited by
                                      #18

                                      Hi, i don't get an error message ! It simpy dont work ;) :^) :sigh: Best regards Croc

                                      M 1 Reply Last reply
                                      0
                                      • C CrocodileBuck

                                        Hi, i don't get an error message ! It simpy dont work ;) :^) :sigh: Best regards Croc

                                        M Offline
                                        M Offline
                                        Mark Salsbery
                                        wrote on last edited by
                                        #19

                                        If you put a breakpoint in OnChar() and run it in the debugger, is it ever hit when you type in the control? If not, put a breakpoint in the CMyEdit constructor.  Is that ever hit?  If not then you didn't use a CMyEdit instead of a CEdit. I'd look at your code if it was in a ZIP - I have no unrar utility. Mark

                                        Mark Salsbery Microsoft MVP - Visual C++ :java:

                                        C 1 Reply Last reply
                                        0
                                        • M Mark Salsbery

                                          If you put a breakpoint in OnChar() and run it in the debugger, is it ever hit when you type in the control? If not, put a breakpoint in the CMyEdit constructor.  Is that ever hit?  If not then you didn't use a CMyEdit instead of a CEdit. I'd look at your code if it was in a ZIP - I have no unrar utility. Mark

                                          Mark Salsbery Microsoft MVP - Visual C++ :java:

                                          C Offline
                                          C Offline
                                          CrocodileBuck
                                          wrote on last edited by
                                          #20

                                          Hi Mr.Salsbery, no problem, here is the zip: http://www.filehosting.at/files/download.php?file=28f8239afa7e8afc1de1773edd074a02 best regards Croc

                                          M 2 Replies 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