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. Update text on one form from another form

Update text on one form from another form

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

    I have a program that displays a dialog box with a series of buttons and a text box for messages. When I select one of the buttons it creates an instance of a module that interfaces to some USB tools. Sometimes the work done by this interface module can take sometime to complete and I would like the interface module to update the text box on the dialog box. Is there an easy way to do this? I am using VC++ 6.0. Eric

    N 1 Reply Last reply
    0
    • B braune

      I have a program that displays a dialog box with a series of buttons and a text box for messages. When I select one of the buttons it creates an instance of a module that interfaces to some USB tools. Sometimes the work done by this interface module can take sometime to complete and I would like the interface module to update the text box on the dialog box. Is there an easy way to do this? I am using VC++ 6.0. Eric

      N Offline
      N Offline
      Nelek
      wrote on last edited by
      #2

      Hi, you can set a control variable associated with the control you want to update, and then access them through a pointer to the window/dialog that has the ownership of those controls. As example (In one of my programms): Form3 has some buttons (m_cbBut1, m_cbBut2) and Form2 has a graphic (m_gGraph1). In Form3 I have a pointer to the Form2 (CFormView* m_pForm2). When I use some of the buttons I put in the message OnButtonXClick something like:

      OnClick ()
      {
      //some code
      m_pForm2->m_gGraph1->Update (); //I make the update of my graphic
      m_pForm2->m_cbBut1F2->ShowWindow (FALSE); //I make invisible a button near the graphic.
      //some code
      return;
      }

      Greetings. -------- M.D.V. If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?

      B 1 Reply Last reply
      0
      • N Nelek

        Hi, you can set a control variable associated with the control you want to update, and then access them through a pointer to the window/dialog that has the ownership of those controls. As example (In one of my programms): Form3 has some buttons (m_cbBut1, m_cbBut2) and Form2 has a graphic (m_gGraph1). In Form3 I have a pointer to the Form2 (CFormView* m_pForm2). When I use some of the buttons I put in the message OnButtonXClick something like:

        OnClick ()
        {
        //some code
        m_pForm2->m_gGraph1->Update (); //I make the update of my graphic
        m_pForm2->m_cbBut1F2->ShowWindow (FALSE); //I make invisible a button near the graphic.
        //some code
        return;
        }

        Greetings. -------- M.D.V. If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?

        B Offline
        B Offline
        braune
        wrote on last edited by
        #3

        How did you arrive with m_pForm2? I am using Dialog instead of Form, would that make a difference? I can not seem to get my control variables to show up. Eric

        K N 2 Replies Last reply
        0
        • B braune

          How did you arrive with m_pForm2? I am using Dialog instead of Form, would that make a difference? I can not seem to get my control variables to show up. Eric

          K Offline
          K Offline
          kanduripavan
          wrote on last edited by
          #4

          hi, have a CClass* (of the class where u have to update) as a dialog box member. Before calling DoModal update this pointer and rest handle with the pointer. Try it.Lets see . Have a nice day

          1 Reply Last reply
          0
          • B braune

            How did you arrive with m_pForm2? I am using Dialog instead of Form, would that make a difference? I can not seem to get my control variables to show up. Eric

            N Offline
            N Offline
            Nelek
            wrote on last edited by
            #5

            I have made it by using the View List of CDocument, because the form is connected to the document through a pDocTemplate. But the principe is the same. You can take a pointer to your dialog, by taking the handler of the window that contains the dialog in you OnInitDialog and recasting it to a CDialog*... Or another possibility is to use the moment you create the dialog to take the pointer. For example: //Instead of this... CDialog newDlg; int nAnswer = newDlg.DoModal (); //... // //Use this // CDialog* m_pOpenedDialog; //Variable to get the connection to the dialog CDialog* newDlg; //here send the pointer to a variable in the other window to connect with m_pOpenedDialog = newDlg; int nAnswer = newDlg->DoModal ();

            Greetings. -------- M.D.V. If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?

            B 1 Reply Last reply
            0
            • N Nelek

              I have made it by using the View List of CDocument, because the form is connected to the document through a pDocTemplate. But the principe is the same. You can take a pointer to your dialog, by taking the handler of the window that contains the dialog in you OnInitDialog and recasting it to a CDialog*... Or another possibility is to use the moment you create the dialog to take the pointer. For example: //Instead of this... CDialog newDlg; int nAnswer = newDlg.DoModal (); //... // //Use this // CDialog* m_pOpenedDialog; //Variable to get the connection to the dialog CDialog* newDlg; //here send the pointer to a variable in the other window to connect with m_pOpenedDialog = newDlg; int nAnswer = newDlg->DoModal ();

              Greetings. -------- M.D.V. If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?

              B Offline
              B Offline
              braune
              wrote on last edited by
              #6

              Maybe I am not explaining this correctly or do not not understand your solution. I will try to explain with example: When I click on a button in my main form (CUsbDlg) it run the following: void CUsbDlg::OnFormatBlock0() { CUsbIo cUsb; //Setup the usb communication (load the bix file) if(!cUsb.CommunicationSetup()) The problem is that I need cUsb to update a Static text box on the CUsbDlg form. There are items that happen within the CommunicationSetup that may take some time. I need to let the user know where we are in the process. Eric

              D 1 Reply Last reply
              0
              • B braune

                Maybe I am not explaining this correctly or do not not understand your solution. I will try to explain with example: When I click on a button in my main form (CUsbDlg) it run the following: void CUsbDlg::OnFormatBlock0() { CUsbIo cUsb; //Setup the usb communication (load the bix file) if(!cUsb.CommunicationSetup()) The problem is that I need cUsb to update a Static text box on the CUsbDlg form. There are items that happen within the CommunicationSetup that may take some time. I need to let the user know where we are in the process. Eric

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

                braune wrote:

                The problem is that I need cUsb to update a Static text box on the CUsbDlg form.

                Ok, so what's the problem? One way to achieve what you want is to have the CUsbIo class post messages back to CUsbDlg. In the handler for those messages, update the static controls.


                "A good athlete is the result of a good and worthy opponent." - David Crow

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

                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