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. Show information in the same dialog after press diferent button

Show information in the same dialog after press diferent button

Scheduled Pinned Locked Moved C / C++ / MFC
c++helptutorialquestion
25 Posts 6 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.
  • M Madhu Nair 0

    antonio343 wrote:

    I need, to show text from other class in the same dialog

    How about making the ShowText function as public and pass a CString variable ;

    void CEjemplo::ShowText(CString strText)
    {
    //CString cadena= _T("Hi, it is a example");
    m_Edit.SetWindowTextW(strText);
    //Add this to invoke DDX updation
    UpdateData(FALSE);
    }

    call the public function of CEjemplo object as,

    void CSomeOtherClass::ShowText()
    {
    CEjemplo oEjemplo;
    CSting strText(_T("Some text from other class"));
    oEjemplo.ShowText(strText);
    }

    A Offline
    A Offline
    antonio343
    wrote on last edited by
    #7

    ok, but.. Where I define strText? And.. to show the text I need the method OnInitDialog in class CEjemplo, but if I add the parameter I need to pass the paramenter to this method and it isn't possible.

    BOOL CEjemplo::OnInitDialog()
    {
    CDialogEx::OnInitDialog();
    ShowText();
    // TODO: Agregue aquí la inicialización adicional

    return TRUE;  // return TRUE unless you set the focus to a control
    // EXCEPCIÓN: las páginas de propiedades OCX deben devolver FALSE
    

    }

    1 Reply Last reply
    0
    • S Software_Developer

      If you want to change or replace all of the text n an edit control , use the CWnd::SetWindowText member function

      CString strText;
      GetDlgItem( IDC_EDIT1 )->SetWindowText( strText );

      CWnd::SetWindowText http://msdn.microsoft.com/en-us/library/yhczy8bz.aspx[^]

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

      What is wrong with this[^]?

      Unrequited desire is character building. OriginalGriff

      S 1 Reply Last reply
      0
      • A antonio343

        ok...when you press a button show a modeless dialog with a edit control to show text. Class view: void Cprueba4View::OnButton2() { CEjemplo *dlgDesc; dlgDesc = new CEjemplo(); dlgDesc->Create( IDD_DIALOG1 ,GetDesktopWindow()); dlgDesc->ShowWindow(1); } In class CEjemplo: void CEjemplo::ShowText(void) { CString cadena= _T("Hi, it is a example"); m_Edit.SetWindowTextW(cadena); } But I need, to show text from other class in the same dialog, that mean, the text, it will be added in the same windows when I press other button. Every button are in the ribbon.

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

        So add a function to your dialog that manages the text, then you can call that function as different buttons are pressed. However, I would say that your design is not the best way of doing things in Windows.

        Unrequited desire is character building. OriginalGriff

        A 1 Reply Last reply
        0
        • L Lost User

          So add a function to your dialog that manages the text, then you can call that function as different buttons are pressed. However, I would say that your design is not the best way of doing things in Windows.

          Unrequited desire is character building. OriginalGriff

          A Offline
          A Offline
          antonio343
          wrote on last edited by
          #10

          I didnt understand you. If you know a better way to do, let me know, please.

          L 1 Reply Last reply
          0
          • L Lost User

            What is wrong with this[^]?

            Unrequited desire is character building. OriginalGriff

            S Offline
            S Offline
            Software_Developer
            wrote on last edited by
            #11

            doooh : :doh: yes, yes indeed.. SetDlgItemText(Dialogbox, IDC_EDITBOX, sString);

            1 Reply Last reply
            0
            • A antonio343

              I didnt understand you. If you know a better way to do, let me know, please.

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

              As I understand it you are changing the content of the dialog by pressing a button on the main form. This will not be a good experience for your users, as most people like to interact with one window at a time. For example: If the user presses a button on the main form and a dialog appears, all user action should now be with that dialog until the dialog is dismissed. If they have to go back to the main form to press a button to change something in the dialog then things get confused. If my understanding of your system is incorrect I apologise for my confusion.

              Unrequited desire is character building. OriginalGriff

              A 1 Reply Last reply
              0
              • L Lost User

                As I understand it you are changing the content of the dialog by pressing a button on the main form. This will not be a good experience for your users, as most people like to interact with one window at a time. For example: If the user presses a button on the main form and a dialog appears, all user action should now be with that dialog until the dialog is dismissed. If they have to go back to the main form to press a button to change something in the dialog then things get confused. If my understanding of your system is incorrect I apologise for my confusion.

                Unrequited desire is character building. OriginalGriff

                A Offline
                A Offline
                antonio343
                wrote on last edited by
                #13

                The idea is it dialog is used to show dates. The app will be a estadistic program, like SPSS, you will have a several variables and if you choose one of this and press a one button, in the dialog will be show the average, and if you after press other button, it will be added to the dialog the frecuency, for example. Due to it, I'd like to get show diferent information from diferent class in the same dialog. Please, help me.

                L 1 Reply Last reply
                0
                • A antonio343

                  The idea is it dialog is used to show dates. The app will be a estadistic program, like SPSS, you will have a several variables and if you choose one of this and press a one button, in the dialog will be show the average, and if you after press other button, it will be added to the dialog the frecuency, for example. Due to it, I'd like to get show diferent information from diferent class in the same dialog. Please, help me.

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

                  Your original message states that this is an MDI application, so it would seem the obvious answer is to show your results in one of the MDI windows. Alternatively put all your selector buttons into the dialog and just use the button handlers to get the data from wherever it is held and display it in the dialog.

                  Unrequited desire is character building. OriginalGriff

                  A 1 Reply Last reply
                  0
                  • L Lost User

                    Your original message states that this is an MDI application, so it would seem the obvious answer is to show your results in one of the MDI windows. Alternatively put all your selector buttons into the dialog and just use the button handlers to get the data from wherever it is held and display it in the dialog.

                    Unrequited desire is character building. OriginalGriff

                    A Offline
                    A Offline
                    antonio343
                    wrote on last edited by
                    #15

                    No, I cant. This windows/dialog is only to show the result. Now, I show each result in one dialog diferent, but I'd like to group all the result in one dialog, and after, I will make a button in this dialog to save the information in a txt for example. But I must to do at this way

                    L D 2 Replies Last reply
                    0
                    • A antonio343

                      No, I cant. This windows/dialog is only to show the result. Now, I show each result in one dialog diferent, but I'd like to group all the result in one dialog, and after, I will make a button in this dialog to save the information in a txt for example. But I must to do at this way

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

                      antonio343 wrote:

                      No, I cant.

                      I have offered two suggestion which would make life easier for you, I cannot think of a third that would be better.

                      Unrequited desire is character building. OriginalGriff

                      1 Reply Last reply
                      0
                      • A antonio343

                        No, I cant. This windows/dialog is only to show the result. Now, I show each result in one dialog diferent, but I'd like to group all the result in one dialog, and after, I will make a button in this dialog to save the information in a txt for example. But I must to do at this way

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

                        You never clarified whether you were using a modal or modeless dialog. I don't think your issue can be addressed until that is made clear.

                        "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

                        A 1 Reply Last reply
                        0
                        • D David Crow

                          You never clarified whether you were using a modal or modeless dialog. I don't think your issue can be addressed until that is made clear.

                          "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

                          A Offline
                          A Offline
                          antonio343
                          wrote on last edited by
                          #18

                          I'm sorry, you are right. It is a modeless dialog. I'm triying use set and get DlgItemText, but maybe I dont know how to use it. I made this:

                          void Cprueba4View::OnButton3()
                          {

                          CString cadena;
                          GetDlgItemText(IDC\_EDIT1, cadena);
                          cadena += "Helloo other time ";
                          SetDlgItemText(IDC\_EDIT1, cadena);
                          

                          }

                          D A 2 Replies Last reply
                          0
                          • A antonio343

                            I'm sorry, you are right. It is a modeless dialog. I'm triying use set and get DlgItemText, but maybe I dont know how to use it. I made this:

                            void Cprueba4View::OnButton3()
                            {

                            CString cadena;
                            GetDlgItemText(IDC\_EDIT1, cadena);
                            cadena += "Helloo other time ";
                            SetDlgItemText(IDC\_EDIT1, cadena);
                            

                            }

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

                            Do not interact with UI controls from any place other than the owning window (the modeless dialog in this case). If you need the modeless dialog to update its controls, send it a message.

                            "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
                            • A antonio343

                              I'm sorry, you are right. It is a modeless dialog. I'm triying use set and get DlgItemText, but maybe I dont know how to use it. I made this:

                              void Cprueba4View::OnButton3()
                              {

                              CString cadena;
                              GetDlgItemText(IDC\_EDIT1, cadena);
                              cadena += "Helloo other time ";
                              SetDlgItemText(IDC\_EDIT1, cadena);
                              

                              }

                              A Offline
                              A Offline
                              antonio343
                              wrote on last edited by
                              #20

                              Ok, finally, I got my answer. I solved of this way: I made a public variable of my dialog class, where is the edit control, in the class view, and I made the windows in the builder. After, when I press a button, I did :

                              void Cprueba4View::OnButton3()
                              {

                              CString cadena;
                              dlgDesc->GetDlgItemText(IDC\_EDIT1, cadena);
                              cadena += "Hello other time ";
                              dlgDesc->SetDlgItemText(IDC\_EDIT1, cadena);
                              dlgDesc->SetFocus();
                              

                              }

                              But now, I have another problem. When I maximize the windows dialog, only it's maximized the windows and not the edit control. why? how can I maximize the windows and the edit control at the same time? I used

                              dlgDesc->ShowWindow(SW\_MAXIMIZE);
                              

                              to maximized

                              D 1 Reply Last reply
                              0
                              • A antonio343

                                Ok, finally, I got my answer. I solved of this way: I made a public variable of my dialog class, where is the edit control, in the class view, and I made the windows in the builder. After, when I press a button, I did :

                                void Cprueba4View::OnButton3()
                                {

                                CString cadena;
                                dlgDesc->GetDlgItemText(IDC\_EDIT1, cadena);
                                cadena += "Hello other time ";
                                dlgDesc->SetDlgItemText(IDC\_EDIT1, cadena);
                                dlgDesc->SetFocus();
                                

                                }

                                But now, I have another problem. When I maximize the windows dialog, only it's maximized the windows and not the edit control. why? how can I maximize the windows and the edit control at the same time? I used

                                dlgDesc->ShowWindow(SW\_MAXIMIZE);
                                

                                to maximized

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

                                antonio343 wrote:

                                how can I maximize the windows and the edit control at the same time?

                                Why can't you use SetWindowPos() on the edit control? It's a window too.

                                "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

                                A 1 Reply Last reply
                                0
                                • D David Crow

                                  antonio343 wrote:

                                  how can I maximize the windows and the edit control at the same time?

                                  Why can't you use SetWindowPos() on the edit control? It's a window too.

                                  "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

                                  A Offline
                                  A Offline
                                  antonio343
                                  wrote on last edited by
                                  #22

                                  I tried this, but it can't run. I did this:

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

                                  // TODO:  Agregue aquí la inicialización adicional
                                  m\_Edit.SetMargins(10,10);
                                  m\_Edit.ShowWindow(SW\_MAXIMIZE);
                                  return TRUE;  // return TRUE unless you set the focus to a control
                                  // EXCEPCIÓN: las páginas de propiedades OCX deben devolver FALSE
                                  

                                  }

                                  is it right? If not.. how I use showWindow()?

                                  D 1 Reply Last reply
                                  0
                                  • A antonio343

                                    I tried this, but it can't run. I did this:

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

                                    // TODO:  Agregue aquí la inicialización adicional
                                    m\_Edit.SetMargins(10,10);
                                    m\_Edit.ShowWindow(SW\_MAXIMIZE);
                                    return TRUE;  // return TRUE unless you set the focus to a control
                                    // EXCEPCIÓN: las páginas de propiedades OCX deben devolver FALSE
                                    

                                    }

                                    is it right? If not.. how I use showWindow()?

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

                                    antonio343 wrote:

                                    I tried this, but it can't run.

                                    Which means what?

                                    antonio343 wrote:

                                    m_Edit.SetMargins(10,10);

                                    Are you thinking that setting a control's margins will also affect it's physical dimensions?

                                    antonio343 wrote:

                                    m_Edit.ShowWindow(SW_MAXIMIZE);

                                    Unless the control's width and height have been changed (see SetWindowPos()), it is already maximized.

                                    "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

                                    A 1 Reply Last reply
                                    0
                                    • D David Crow

                                      antonio343 wrote:

                                      I tried this, but it can't run.

                                      Which means what?

                                      antonio343 wrote:

                                      m_Edit.SetMargins(10,10);

                                      Are you thinking that setting a control's margins will also affect it's physical dimensions?

                                      antonio343 wrote:

                                      m_Edit.ShowWindow(SW_MAXIMIZE);

                                      Unless the control's width and height have been changed (see SetWindowPos()), it is already maximized.

                                      "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

                                      A Offline
                                      A Offline
                                      antonio343
                                      wrote on last edited by
                                      #24

                                      m_Edit.SetMargins(10,10);

                                      is so that the text don't appear next to the border. Ok, I will try with SetWindowPos. I will tell you my progress

                                      A 1 Reply Last reply
                                      0
                                      • A antonio343

                                        m_Edit.SetMargins(10,10);

                                        is so that the text don't appear next to the border. Ok, I will try with SetWindowPos. I will tell you my progress

                                        A Offline
                                        A Offline
                                        antonio343
                                        wrote on last edited by
                                        #25

                                        I dont know how to use this function. Please, teach me.

                                        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