Click to See Complete Forum and Search --> : Can you change displayed data on the current dialog?


John Kelley
April 10th, 1999, 09:11 PM
I struggled for while to find a way to change the diplayed data on a single dialog. I found a solution, but I think there must be a better way.

What I wanted to do was enter some data into an edit box, click a "Calculate" button right next to this box, and have the resulting data (after calculation) display in a read-only edit box at the bottom of the dialog. But I don't want the dialog to close.

The following is my temporary solution, assuming somebody can tell me a better way:

// Within DataDlg.cpp
...
void CDataDlg::OnCalculate()
CString Input; // Same type as m_Input_Data
CString Output; // Will be modification of Input
CDataDlg OutputDlg; // Declare a new data dialog

Input = m_Input_Data;
Output = m_Input_Data;
// Do other modifications to Output here

CDataDlg::OnOK(); // I had to get rid of the dialog so that I could...

// create an exact replica of previous dialog
// but with member variables initialized to Input & Output
OutputDlg.m_Input_Data = Input;
OutputDlg.m_Output_Data = Output;
OutputDlg.DoModal();

}

While this gives a pretty good illusion of modifying the same dialog, there is a flicker when the first dialog closes and the second one opens. Is there a way to have the m_Output_Data appear in the original dialog? I have tried UpdateData, Redraw, etc. but this dialog always stayed the same.

Thanks for any help!

"Try not. Do, or do not. There is no try." - Yoda

April 11th, 1999, 03:01 AM
Use ONE dialog.
Attach a CEdit to the the control (use classwizard)- I've called it CEditCtrl here:

OnCalculate()// the button clik handler
{
CString szVal;
m_EditCtrl.GetWindowText(szVal);
// do your calc, setting result into szVal;
m_EditCtrl.SetWindowText(szVal);
}

that's all you need.

April 11th, 1999, 03:05 AM
(addendum to my initial response)

OK ... I've re-read your message and realsised I slightly misread it.

You need TWO CEdits - your read from one, do your calc, then write to the other. The GetWindowText(), SetWindowText() stuff is right - you just do it to two different controls.

John Kelley
April 12th, 1999, 12:11 PM
Okay, I'm afraid I still don't get it. By 'attach the CEdit to the control,' do you mean to the Edit Box I'm using to get my data? If so, how do you attach it? I created a class CEditCtrl based on the CEdit class, but I can't figure out how to access the member variable from the Edit Box.

Or do you mean I should replace the Edit Box with a CEditCtrl type? If this is the case, the class wizard doesn't give me a direct option, so is this something I need to code manually? (This shouldn't be a problem, but your reply sounded like ClassWizard should somehow take care of the details so I'd rather do that, if possible.)

Thanks again!

"Try not. Do, or do not. There is no try." - Yoda

Gomez Addams
April 12th, 1999, 12:36 PM
I think that the class wizard can do this for you but it's easy to do yourself.

In the dialog's definition, there will be a line like this :

//{{AFX_DATA(CMyDlg)
enum { IDD = IDD_MY_DIALOG };
//}}AFX_DATA

insert a variable like CEdit m_edit; right below the enum.
Then, in the code for the dialog there will be this :

void CMyDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CListHdrDlg)
//}}AFX_DATA_MAP
}

Add a line like DDX_Control(pDX, IDC_EDITCTRL, m_edit);
within the AFX_DATA_MAP statements. This will have the effect
of associating your edit control object to the resource IDC_EDITCTRL.

Do this for each of your edit controls. Then, the statements mentioned
before will work.

Or, GetDlgItemInt and SetDlgItemInt can be used like this :

int x = GetDlgItemInt( IDC_EDITCTRL );
x = ReCalculateX( x );
GetDlgItemInt( IDC_EDITCTRL, x )