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