本文整理汇总了C++中wxTextCtrl::LoadFile方法的典型用法代码示例。如果您正苦于以下问题:C++ wxTextCtrl::LoadFile方法的具体用法?C++ wxTextCtrl::LoadFile怎么用?C++ wxTextCtrl::LoadFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wxTextCtrl
的用法示例。
在下文中一共展示了wxTextCtrl::LoadFile方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OnViewMsg
void MyFrame::OnViewMsg(wxCommandEvent& WXUNUSED(event))
{
#if wxUSE_FILEDLG
// first, choose the file
static wxString s_dir, s_file;
wxFileDialog dialog(this, wxT("Open an email message file"),
s_dir, s_file);
if ( dialog.ShowModal() != wxID_OK )
return;
// save for the next time
s_dir = dialog.GetDirectory();
s_file = dialog.GetFilename();
wxString filename = dialog.GetPath();
// load it and search for Content-Type header
wxTextFile file(filename);
if ( !file.Open() )
return;
wxString charset;
static const wxChar *prefix = wxT("Content-Type: text/plain; charset=");
const size_t len = wxStrlen(prefix);
size_t n, count = file.GetLineCount();
for ( n = 0; n < count; n++ )
{
wxString line = file[n];
if ( !line )
{
// if it is an email message, headers are over, no need to parse
// all the file
break;
}
if ( line.Left(len) == prefix )
{
// found!
const wxChar *pc = line.c_str() + len;
if ( *pc == wxT('"') )
pc++;
while ( *pc && *pc != wxT('"') )
{
charset += *pc++;
}
break;
}
}
if ( !charset )
{
wxLogError(wxT("The file '%s' doesn't contain charset information."),
filename.c_str());
return;
}
// ok, now get the corresponding encoding
wxFontEncoding fontenc = wxFontMapper::Get()->CharsetToEncoding(charset);
if ( fontenc == wxFONTENCODING_SYSTEM )
{
wxLogError(wxT("Charset '%s' is unsupported."), charset.c_str());
return;
}
m_textctrl->LoadFile(filename);
if ( fontenc == wxFONTENCODING_UTF8 ||
!wxFontMapper::Get()->IsEncodingAvailable(fontenc) )
{
// try to find some similar encoding:
wxFontEncoding encAlt;
if ( wxFontMapper::Get()->GetAltForEncoding(fontenc, &encAlt) )
{
wxEncodingConverter conv;
if (conv.Init(fontenc, encAlt))
{
fontenc = encAlt;
m_textctrl -> SetValue(conv.Convert(m_textctrl -> GetValue()));
}
else
{
wxLogWarning(wxT("Cannot convert from '%s' to '%s'."),
wxFontMapper::GetEncodingDescription(fontenc).c_str(),
wxFontMapper::GetEncodingDescription(encAlt).c_str());
}
}
else
wxLogWarning(wxT("No fonts for encoding '%s' on this system."),
wxFontMapper::GetEncodingDescription(fontenc).c_str());
}
// and now create the correct font
if ( !DoEnumerateFamilies(false, fontenc, true /* silent */) )
//.........这里部分代码省略.........