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 return value after user input

how to return value after user input

Scheduled Pinned Locked Moved C / C++ / MFC
c++comhelptutorialquestion
27 Posts 4 Posters 37 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.
  • M Member 2119844

    well sir, i am just learning and doing work. i don't have much idea about it. so i request for help. i am trying this from all most a week. i google it and did not found simillar to what i am looking for. maybe because i don't have enough knowledge. so.. hoping to get help from some kind heart.

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

    Member 2119844 wrote:

    hoping to get help from some kind heart.

    Which is what I offered to you yesterday. Use the features of the CDialog and its controls rather than struggling to try and interpret individual keystrokes that are already captured for you. Text boxes have events that you can capture as characters are entered into them, which allow you to check and/or modify their content. The CDialog class has a function that will capture or refresh all the data between the dialog and the associated class variables etc.

    One of these days I'm going to think of a really clever signature.

    M 1 Reply Last reply
    0
    • L Lost User

      Member 2119844 wrote:

      hoping to get help from some kind heart.

      Which is what I offered to you yesterday. Use the features of the CDialog and its controls rather than struggling to try and interpret individual keystrokes that are already captured for you. Text boxes have events that you can capture as characters are entered into them, which allow you to check and/or modify their content. The CDialog class has a function that will capture or refresh all the data between the dialog and the associated class variables etc.

      One of these days I'm going to think of a really clever signature.

      M Offline
      M Offline
      Member 2119844
      wrote on last edited by
      #22

      Dear sir, i really appreciate your and Santhosh suggestion. i do. but the thing is bit difference what i am looking for. maybe i am not able to describe very well, what i am looking for. sorry for that. because my English is not good enough. so please don't get me wrong. once again i am trying to explain what i need to do. and what i come up to. i need to make function that return value after press Enter key. not directly and not in any other way. but from function when it call from outer class. this is the event when user press button in dlg class.

      void CRetValTestDlg::OnGetString()
      {
      m_TxInput.InFlag = false;
      CString s = m_TxInput.GetString();
      m_TxOutput.SetWindowText (s);
      }

      and this is CMyTextBox calss member function which is call from dlg class on button press. which need to return value.

      CString CMyTextBox::GetString()
      {
      if (InFlag == true)
      return RetVal;
      return "";
      }

      now i have come upto this

      CString CMyTextBox::GetString()
      {
      while (InFalg != true) // this is infinite loop but
      {
      DoEvents(); // doEvents hole for it so it wait until it get event
      if (InFlag == true) // the InFlag = true when user press Enter;
      return RetVal; // and return value
      }
      return ""; // else return "";
      }

      this is work. but when i use While and DoEvents the processor took lot of work. it took all most 50% of CPU used. and which is really not good. i think. and some time it does not come out from that loop when user left so when the program close. it remain in task manager. and CUP running. now What i am looking for is -> is there any other way to wait till event. maybe using CEvent or CallBack or threading or something else. without using lot of CPU used. because i don't know anything about them. i have never use.

      CString CMyTextBox::GetString()
      {
      //====================== Here i am looking for help =============================
      // wait for event here or WaitTill (InFlag !=true); in this line i need help.
      //==================================================================================
      if (InFlag == true)
      return RetVal;
      return "";
      }

      i hope this time i could able to tell what i need for. this is really important for me. so Please Please Help.

      L 1 Reply Last reply
      0
      • M Member 2119844

        Dear sir, i really appreciate your and Santhosh suggestion. i do. but the thing is bit difference what i am looking for. maybe i am not able to describe very well, what i am looking for. sorry for that. because my English is not good enough. so please don't get me wrong. once again i am trying to explain what i need to do. and what i come up to. i need to make function that return value after press Enter key. not directly and not in any other way. but from function when it call from outer class. this is the event when user press button in dlg class.

        void CRetValTestDlg::OnGetString()
        {
        m_TxInput.InFlag = false;
        CString s = m_TxInput.GetString();
        m_TxOutput.SetWindowText (s);
        }

        and this is CMyTextBox calss member function which is call from dlg class on button press. which need to return value.

        CString CMyTextBox::GetString()
        {
        if (InFlag == true)
        return RetVal;
        return "";
        }

        now i have come upto this

        CString CMyTextBox::GetString()
        {
        while (InFalg != true) // this is infinite loop but
        {
        DoEvents(); // doEvents hole for it so it wait until it get event
        if (InFlag == true) // the InFlag = true when user press Enter;
        return RetVal; // and return value
        }
        return ""; // else return "";
        }

        this is work. but when i use While and DoEvents the processor took lot of work. it took all most 50% of CPU used. and which is really not good. i think. and some time it does not come out from that loop when user left so when the program close. it remain in task manager. and CUP running. now What i am looking for is -> is there any other way to wait till event. maybe using CEvent or CallBack or threading or something else. without using lot of CPU used. because i don't know anything about them. i have never use.

        CString CMyTextBox::GetString()
        {
        //====================== Here i am looking for help =============================
        // wait for event here or WaitTill (InFlag !=true); in this line i need help.
        //==================================================================================
        if (InFlag == true)
        return RetVal;
        return "";
        }

        i hope this time i could able to tell what i need for. this is really important for me. so Please Please Help.

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

        All I can do is repeat what I said before. Use the events and notifications of the CDialog class. The default action when user presses the enter key is to call the OnOK() function. You add code to that method to capture the text using the UpdateData() function. Let the dialog do the work for you. Maybe you should spend some time reading the documentation about Dialog Boxes[^] in general, and the CDialog[^] class in particular. You may also find that the documentation is available in your own language.

        One of these days I'm going to think of a really clever signature.

        M 1 Reply Last reply
        0
        • L Lost User

          All I can do is repeat what I said before. Use the events and notifications of the CDialog class. The default action when user presses the enter key is to call the OnOK() function. You add code to that method to capture the text using the UpdateData() function. Let the dialog do the work for you. Maybe you should spend some time reading the documentation about Dialog Boxes[^] in general, and the CDialog[^] class in particular. You may also find that the documentation is available in your own language.

          One of these days I'm going to think of a really clever signature.

          M Offline
          M Offline
          Member 2119844
          wrote on last edited by
          #24

          ok i will try. but. as you said. >> Use the events and notifications of the CDialog class. Which Events and Notification? i use this to block call OnOk() while press Enter Key.

          BOOL CRetValTestDlg::PreTranslateMessage( MSG* pMsg )
          {
          if (pMsg->message == WM_KEYDOWN)
          {
          if ((pMsg->wParam == VK_RETURN) || (pMsg->wParam == VK_ESCAPE))
          pMsg->wParam = NULL;// VK_TAB;
          }

          return CDialog::PreTranslateMessage( pMsg );
          

          }

          how dialog do my work. it would be great if i could get some sample code. i have spend lot of time to read and search. i did not find or i did not understand. so i request for help. if i understand, i may not request for help.

          L 1 Reply Last reply
          0
          • M Member 2119844

            ok i will try. but. as you said. >> Use the events and notifications of the CDialog class. Which Events and Notification? i use this to block call OnOk() while press Enter Key.

            BOOL CRetValTestDlg::PreTranslateMessage( MSG* pMsg )
            {
            if (pMsg->message == WM_KEYDOWN)
            {
            if ((pMsg->wParam == VK_RETURN) || (pMsg->wParam == VK_ESCAPE))
            pMsg->wParam = NULL;// VK_TAB;
            }

            return CDialog::PreTranslateMessage( pMsg );
            

            }

            how dialog do my work. it would be great if i could get some sample code. i have spend lot of time to read and search. i did not find or i did not understand. so i request for help. if i understand, i may not request for help.

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

            I don't know what you are hoping to achieve with the code above, but it is not likely to help you. Please spend some time reading the two links I gave in my previous answer, so you understand how dialogs operate.

            One of these days I'm going to think of a really clever signature.

            M 1 Reply Last reply
            0
            • L Lost User

              I don't know what you are hoping to achieve with the code above, but it is not likely to help you. Please spend some time reading the two links I gave in my previous answer, so you understand how dialogs operate.

              One of these days I'm going to think of a really clever signature.

              M Offline
              M Offline
              Member 2119844
              wrote on last edited by
              #26

              Thank you.

              1 Reply Last reply
              0
              • M Member 2119844

                Hi All, i need to return input value after press enter. how to make it. need little help. the main think here that i have to make function that return value after press Enter. here is link of project file. https://skydrive.live.com/redir?resid=78B222720843DE16!116&authkey=!AAjKOKZHSd-q9lI i have a dialog box with 2 EditBox (m_TxInput and m_TxOutPut) and 2 Button for (GetString and GetNumber) i made class CMyTextBox for m_TxInput . here is code below. i have 2 function GetString and GetNumber in CMyTextBox Class. i am calling these function on button down in dlg.

                /////////////////////////////////////////////////////////////////////////////
                // CMyTextBox window

                class CMyTextBox : public CEdit
                {
                // Construction
                public:
                CMyTextBox();

                // Attributes
                public:

                // Operations
                public:

                bool InFlag; // After Press Enter InFlag = true;
                CString RetVal; // store return value
                

                // Overrides
                // ClassWizard generated virtual function overrides
                //{{AFX_VIRTUAL(CMyTextBox)
                //}}AFX_VIRTUAL

                // Implementation
                public:
                CString GetString();
                double GetNumber();
                virtual ~CMyTextBox();

                // Generated message map functions
                

                protected:
                //{{AFX_MSG(CMyTextBox)
                afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
                //}}AFX_MSG

                DECLARE\_MESSAGE\_MAP()
                

                };

                // CPP file======================================================

                // CMyTextBox message handlers

                void CMyTextBox::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
                {
                // TODO: Add your message handler code here and/or call default
                if (nFlags == 28) // Enter press
                GetWindowText(RetVal);
                CEdit::OnKeyDown(nChar, nRepCnt, nFlags);
                }

                double CMyTextBox::GetNumber()
                {
                // how to get return here after press enter by user
                if (InFlag == true)
                return atof(RetVal);
                return 0;
                }

                CString CMyTextBox::GetString()
                {
                // how to get return here after press enter by user
                if (InFlag == true)
                return RetVal;
                return "";
                }

                Thanks Amrit

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

                By default, a dialog's OnOK() handler will be called when you "press" the Enter key from within an edit control. If you would rather the edit control do something else, check out the ES_WANTRETURN style.

                "One man's wage rise is another man's price increase." - Harold Wilson

                "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                "Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous

                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