Click here to Skip to main content
15,890,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello to all,

I am new to visual c++ MFC programming.
And I want to make dialog based application in which if I press a button(suppose "read") one another dialog box is open and in its Edit box I will pass path of some file(suppose c:\code\project.txt) and when I press OPEN button I can show all content of that particular file in Edit Box of that Dialog box.

I can open the path through CFileDialog class but when I press OPEN button it is not working. So how to manage that thing. And I want to do same thing for WRITE button in which write in file through edit box.

So help me solve this problem..And help me to learn how to manage more than dialog box and transfer data through that.

Thank you in advance
Posted

Please read this[^] article. I hope it helps.
 
Share this answer
 
The CFileDialog does not open your file. It is used to select files. The button is labeled 'Open' when passing TRUE as first parameter (File Open dialog).

When calling DoModal() of the file dialog, check the return value. If it is IDOK, get the file name by the GetPathName() member function and pass it to the dialog with the edit control:
C++
CFileDialog FileDlg(TRUE, ...);
if (IDOK == FileDlg.DoModal())
{
    CShowFileDlg ShowDlg; // your dialog with the edit control
    // Pass file name to dialog.
    ShowDlg.m_strFileName = FileDlg.GetPathName();
    ShowDialog().DoModal();
}


The CShowFileDialog should be created using the dialog resource editor adding a multi line edit control:
C++
class CShowFileDialog : public CDialog
{
...
public:
    CEdit m_edit; // the edit control (must be added using resource editor)
    CString m_strFileName;
...
};

...
DDX_Control(pDX, IDC_EDIT1, m_edit);
...
BOOL CShowFileDlg::OnInitDialog()
{
    CDialog::OnInitDialog();

    // - Open file m_strFileName.
    //   Choose you file open/read method.
    CString str;
    // - Read content into to string.
    // - Close file.
    // - Copy string to edit control.
    m_edit.SetWindowText(str.GetString());
    return TRUE;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900