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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Edit Box use [Solved]

Edit Box use [Solved]

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

    Hi to all. I'm not very good at English, so be lenient. I am a beginner in MFC. I created a tab control which uses dialogs using MFC dialog base. I created clases for each dialog. Iwould like to know how to retrieve the value of an edit box located in my class OngletOne with the class MainWinDlg

    //OngletOne.h

    class OngletOne : public CDialogEx
    {
    DECLARE_DYNAMIC(OngletOne)

    public:
    OngletOne(CWnd* pParent = NULL); // standard constructor
    virtual ~OngletOne();

    // Dialog Data
    enum { IDD = IDD_FORMVIEW };

    protected:
    void Initi();
    virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support

    DECLARE\_MESSAGE\_MAP()
    

    public:
    CEdit m_nom;

    };

    // OngletOne dialog

    IMPLEMENT_DYNAMIC(OngletOne, CDialogEx)

    OngletOne::OngletOne(CWnd* pParent /*=NULL*/)
    : CDialogEx(OngletOne::IDD, pParent)
    {

    }

    OngletOne::~OngletOne()
    {
    }

    void OngletOne::DoDataExchange(CDataExchange* pDX)
    {
    CDialogEx::DoDataExchange(pDX);
    DDX_Control(pDX, IDC_EDIT1, m_nom);
    }

    BEGIN_MESSAGE_MAP(OngletOne, CDialogEx)
    ON_EN_CHANGE(IDC_EDIT1, &OngletOne::OnEnChangeEdit1)
    END_MESSAGE_MAP()

    // OngletOne message handlers
    void OngletOne::Initi()
    {
    m_nom.LimitText(25);
    }

    BOOL OngletOne::OnInitDialog()
    {
    CDialogEx::OnInitDialog();

    // TODO:  Add extra initialization here
    Initi();
    
    return TRUE;  // return TRUE unless you set the focus to a control
    // EXCEPTION: OCX Property Pages should return FALSE
    

    }

    In my MainWinDlg, I do this:

    OngletOne *Onglet1;
    CString edit;
    Onglet1 = new OngletOne;
    OngletOne->GetDlgItemText(IDC_EDIT1, edit);
    MessageBox(edit,0,0);

    BUT IT SHOW NOTHING. PLEASE I NEED HELP.

    J A 2 Replies Last reply
    0
    • F Fawaz Ajani

      Hi to all. I'm not very good at English, so be lenient. I am a beginner in MFC. I created a tab control which uses dialogs using MFC dialog base. I created clases for each dialog. Iwould like to know how to retrieve the value of an edit box located in my class OngletOne with the class MainWinDlg

      //OngletOne.h

      class OngletOne : public CDialogEx
      {
      DECLARE_DYNAMIC(OngletOne)

      public:
      OngletOne(CWnd* pParent = NULL); // standard constructor
      virtual ~OngletOne();

      // Dialog Data
      enum { IDD = IDD_FORMVIEW };

      protected:
      void Initi();
      virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support

      DECLARE\_MESSAGE\_MAP()
      

      public:
      CEdit m_nom;

      };

      // OngletOne dialog

      IMPLEMENT_DYNAMIC(OngletOne, CDialogEx)

      OngletOne::OngletOne(CWnd* pParent /*=NULL*/)
      : CDialogEx(OngletOne::IDD, pParent)
      {

      }

      OngletOne::~OngletOne()
      {
      }

      void OngletOne::DoDataExchange(CDataExchange* pDX)
      {
      CDialogEx::DoDataExchange(pDX);
      DDX_Control(pDX, IDC_EDIT1, m_nom);
      }

      BEGIN_MESSAGE_MAP(OngletOne, CDialogEx)
      ON_EN_CHANGE(IDC_EDIT1, &OngletOne::OnEnChangeEdit1)
      END_MESSAGE_MAP()

      // OngletOne message handlers
      void OngletOne::Initi()
      {
      m_nom.LimitText(25);
      }

      BOOL OngletOne::OnInitDialog()
      {
      CDialogEx::OnInitDialog();

      // TODO:  Add extra initialization here
      Initi();
      
      return TRUE;  // return TRUE unless you set the focus to a control
      // EXCEPTION: OCX Property Pages should return FALSE
      

      }

      In my MainWinDlg, I do this:

      OngletOne *Onglet1;
      CString edit;
      Onglet1 = new OngletOne;
      OngletOne->GetDlgItemText(IDC_EDIT1, edit);
      MessageBox(edit,0,0);

      BUT IT SHOW NOTHING. PLEASE I NEED HELP.

      J Offline
      J Offline
      jeron1
      wrote on last edited by
      #2

      Have you tried Onglet1->DoModal()?

      1 Reply Last reply
      0
      • F Fawaz Ajani

        Hi to all. I'm not very good at English, so be lenient. I am a beginner in MFC. I created a tab control which uses dialogs using MFC dialog base. I created clases for each dialog. Iwould like to know how to retrieve the value of an edit box located in my class OngletOne with the class MainWinDlg

        //OngletOne.h

        class OngletOne : public CDialogEx
        {
        DECLARE_DYNAMIC(OngletOne)

        public:
        OngletOne(CWnd* pParent = NULL); // standard constructor
        virtual ~OngletOne();

        // Dialog Data
        enum { IDD = IDD_FORMVIEW };

        protected:
        void Initi();
        virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support

        DECLARE\_MESSAGE\_MAP()
        

        public:
        CEdit m_nom;

        };

        // OngletOne dialog

        IMPLEMENT_DYNAMIC(OngletOne, CDialogEx)

        OngletOne::OngletOne(CWnd* pParent /*=NULL*/)
        : CDialogEx(OngletOne::IDD, pParent)
        {

        }

        OngletOne::~OngletOne()
        {
        }

        void OngletOne::DoDataExchange(CDataExchange* pDX)
        {
        CDialogEx::DoDataExchange(pDX);
        DDX_Control(pDX, IDC_EDIT1, m_nom);
        }

        BEGIN_MESSAGE_MAP(OngletOne, CDialogEx)
        ON_EN_CHANGE(IDC_EDIT1, &OngletOne::OnEnChangeEdit1)
        END_MESSAGE_MAP()

        // OngletOne message handlers
        void OngletOne::Initi()
        {
        m_nom.LimitText(25);
        }

        BOOL OngletOne::OnInitDialog()
        {
        CDialogEx::OnInitDialog();

        // TODO:  Add extra initialization here
        Initi();
        
        return TRUE;  // return TRUE unless you set the focus to a control
        // EXCEPTION: OCX Property Pages should return FALSE
        

        }

        In my MainWinDlg, I do this:

        OngletOne *Onglet1;
        CString edit;
        Onglet1 = new OngletOne;
        OngletOne->GetDlgItemText(IDC_EDIT1, edit);
        MessageBox(edit,0,0);

        BUT IT SHOW NOTHING. PLEASE I NEED HELP.

        A Offline
        A Offline
        Albert Holguin
        wrote on last edited by
        #3

        Well, since you're using a CEdit anyway, why not use one of his own methods to get the text:

        OngletOne *Onglet1;
        CString edit;
        Onglet1 = new OngletOne;
        OngletOne->m_nom.GetLine(0, edit);
        MessageBox(edit,0,0);

        Edit: I also just noticed that you call new and never actually "create" the dialog. You have to create it or else the windows don't really exist (so when you ask for values inside the windows, well, you either get nothing, an error, or a crash). See CDialog::Create() for a modeless dialog or a CDialog::DoModal() for a modal dialog.

        F 1 Reply Last reply
        0
        • A Albert Holguin

          Well, since you're using a CEdit anyway, why not use one of his own methods to get the text:

          OngletOne *Onglet1;
          CString edit;
          Onglet1 = new OngletOne;
          OngletOne->m_nom.GetLine(0, edit);
          MessageBox(edit,0,0);

          Edit: I also just noticed that you call new and never actually "create" the dialog. You have to create it or else the windows don't really exist (so when you ask for values inside the windows, well, you either get nothing, an error, or a crash). See CDialog::Create() for a modeless dialog or a CDialog::DoModal() for a modal dialog.

          F Offline
          F Offline
          Fawaz Ajani
          wrote on last edited by
          #4

          I did this:

          OngletOne *Onglet1;
          CString edit;
          Onglet1 = new OngletOne;
          Onglet1->Create(IDD_FORMVIEW, this);
          Onglet1->m_nom.GetLine(0, edit);
          MessageBox(edit,0,0);

          But it didn't work. :((

          L A 2 Replies Last reply
          0
          • F Fawaz Ajani

            I did this:

            OngletOne *Onglet1;
            CString edit;
            Onglet1 = new OngletOne;
            Onglet1->Create(IDD_FORMVIEW, this);
            Onglet1->m_nom.GetLine(0, edit);
            MessageBox(edit,0,0);

            But it didn't work. :((

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

            Fawaz Ajani wrote:

            But it didn't work.

            You need to look at what you are doing here, you create the dialog and immediately try to capture some data before the edit control has received any information. Try stepping through your code with the debugger to see exactly what is going on and what are the values of all the varibles at each stage. You may like to work through this sample[^] to see how it should be done.

            F 1 Reply Last reply
            0
            • F Fawaz Ajani

              I did this:

              OngletOne *Onglet1;
              CString edit;
              Onglet1 = new OngletOne;
              Onglet1->Create(IDD_FORMVIEW, this);
              Onglet1->m_nom.GetLine(0, edit);
              MessageBox(edit,0,0);

              But it didn't work. :((

              A Offline
              A Offline
              Albert Holguin
              wrote on last edited by
              #6

              I agree with what Richard said, you just created the controls, it's probably blank.

              F 1 Reply Last reply
              0
              • L Lost User

                Fawaz Ajani wrote:

                But it didn't work.

                You need to look at what you are doing here, you create the dialog and immediately try to capture some data before the edit control has received any information. Try stepping through your code with the debugger to see exactly what is going on and what are the values of all the varibles at each stage. You may like to work through this sample[^] to see how it should be done.

                F Offline
                F Offline
                Fawaz Ajani
                wrote on last edited by
                #7

                It works!!! thanks!!! god bless you!!!!

                L 1 Reply Last reply
                0
                • A Albert Holguin

                  I agree with what Richard said, you just created the controls, it's probably blank.

                  F Offline
                  F Offline
                  Fawaz Ajani
                  wrote on last edited by
                  #8

                  I see. I did it. it work now!

                  A 1 Reply Last reply
                  0
                  • F Fawaz Ajani

                    It works!!! thanks!!! god bless you!!!!

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

                    You are welcome; good luck with the rest of your development.

                    F 1 Reply Last reply
                    0
                    • F Fawaz Ajani

                      I see. I did it. it work now!

                      A Offline
                      A Offline
                      Albert Holguin
                      wrote on last edited by
                      #10

                      BTW, your example (new,create, and grab the value) would work correctly upon create if you filled in a default value within the OnInitDialog() call of the dialog that owns the control. When working with dialogs, OnInitDialog() is the appropriate place to fill in controls with default values.

                      1 Reply Last reply
                      0
                      • L Lost User

                        You are welcome; good luck with the rest of your development.

                        F Offline
                        F Offline
                        Fawaz Ajani
                        wrote on last edited by
                        #11

                        thanks!!!:thumbsup:

                        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