Adsense code (2021-10-05)

Monday, August 25, 2014

Code::Blocks + wxWidgets + wxSmith, to open text file with wxFileDialog

This video show steps to create wxWidgets project in Code::Blocks, using wxSmith, to open text file with wxFileDialog.



The only programmatic code is in wxTextFileFrame::OnMenuOpenSelected() of the file wxTextFileMain.cpp.
void wxTextFileFrame::OnMenuOpenSelected(wxCommandEvent& event)
{
    wxTextFile file;
    wxString text;

    int result;
    result = FileDialog1->ShowModal();
    if(result==wxID_OK){
        SetTitle(FileDialog1->GetPath());

        file.Open(FileDialog1->GetPath());
        for(size_t i=0; i<file.GetLineCount(); i++){
            text << file.GetLine(i) << _T("\r\n");
        }
        file.Close();
        TextCtrl1->SetValue(text);
    }

}


And also include wx/textfile.h.
#include <wx/textfile.h>