0
votes

I am a new comer in MFC programming. I have already wrote a program, and I want to display the program in a graphical interface. So I use MFC dialog to realize it, but it does not work when runs.

Once the OK button is clicked :

void CTest1Dlg::OnBnClickedOk()
{
  UpdateData();
  FILE *stream; 
  freopen_s( &stream, "out_file.ps", "w", stdout ); // reopen stream as .ps
  if (mode == 1)                                    //main() in my code 
  {
    ActiveAuthoring();
  }
  else if (mode == 0)
  {
    XYAuthoring();
  }
  else 
  {
    ActiveAuthoring();
  }
  cout<<"showpage"<<endl;
  UpdateData(FALSE);
  OnOK();
}

My code is in converter.cpp, so first I change converter.cpp to converter.h and include it in Test1Dlg.cpp. And then when the OK button click run the main() in my code.

However, I discover that it seems the parameter does not transfer from the graphical interface to my code, although I relevant the edit control box to every parameter. So the dialog does not work. Could some one help me?

EDIT

this

The eight edit control boxes are the parameters I used in my coverter.cpp.

My code is aim to use eight parameters to generate some strings, these strings are saved in a file named as out_file which format is .ps.

1
What is "stdout"? Do you mean to write to console? I think MFC cannot directly write to console. Something like AttachConsole has to be called. - raj raj
@doctorlove I have updated my problem. There are eight parameters in my code as showed in pic. - Qingyao Li
@rajraj Not exactly. My code generate some strings based on eight parameters, and save them in out_file.ps. - Qingyao Li
Show us more code and tell us what exactly does not work. And where is cout supposed to go ? - Jabberwocky
Not understanding what you want ?? - Santosh Dhanawade

1 Answers

0
votes

There are two basic ways you get data from dialog controls to "your code"... if you're using the Visual Studio dialog editor and adding the controls there, it will generate code inside of virtual void DoDataExchange(CDataExchange* pDX) for you to move data to and from your controls when the dialog gets initialized and terminates. You'll have a line like DDX_Text(pDX, IDC_DIGITS, m_Digits); that the IDE adds that does the exchange. You can also just set and get the data directly if you wanted, e.g. GetDlgItem( IDC_DIGITS )->GetWindowText( m_Digits );