I am using the MFC dialog application.
There are 3 edit box, add1, add2 and sum
and a button "add",
when exectuing, I input add1, add2, and use the "add" function dlg.m_sum=dlg.m_add1+dlg.m_add2
how to make the sum appears in the "sum" edit box? Do I have to add a view class or how to modify the OnPaint?
I now only have add.cpp and addDlg.cpp

in the OnButtonAdd() event handler for the button
1. assume m_sum, m_add1 and m_add2 are integer class member variables which were defined using ClassWizard (VC++ 6.0 compiler), just call UpdateData() after setting m_sum = m_add1 + m_add2.

void OnButtonAdd()
{
   // move window text into member variables
   UpdateData(TRUE); 
   m_sum = m_dat1 + m_data2;
   // move data member variables back to windows
   UpdateData(FALSE);
}

Great !! thank you,
this I don't even have to define a new dlg instance

DO you know how to write this add1, add2, sum values into 2 excel file which I could read and write through added buttons on this dialog box?

I know how to read and write .xls file,
but I just don't know how to save these "add1","add2","sum" into 3 columns in .xls file and how to extract them into these 3 edit box again if I add a button called "ReadLastStored"

in the OnButtonAdd() event handler for the button
1. assume m_sum, m_add1 and m_add2 are integer class member variables which were defined using ClassWizard (VC++ 6.0 compiler), just call UpdateData() after setting m_sum = m_add1 + m_add2.

void OnButtonAdd()
{
   // move window text into member variables
   UpdateData(TRUE); 
   m_sum = m_dat1 + m_data2;
   // move data member variables back to windows
   UpdateData(FALSE);
}

very similar to the code I already posted. Assume you have a Read button Note: there are other c++ ways to convert from std::string to ints, what I show below works most of the time but will not catch errors in the data read from the xls file or integer overflow problems.

void OnButtonRead()
{
    // do something to read the xls file into member 
    // this assumes the data is read into std::string object
    string add1 = ??? // read xls
    string add2 = ??? // read from xls
    m_add1 = atoi(add1.c_str());
    m_add2 = atoi(add2.c_str());
    m_sum = m_add1 + m_add2;
    UpdateData(FALSE);
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.