我正在使用 wxWidgets 在 Ubuntu Linux 上进行开发,但在 wxFrame 内的文件系统上显示 html 文件时遇到问题。wxFrame 弹出,但窗口中没有 HTML 内容。
这是我的 OnInit() 函数的片段:
//wxIMPLEMENT_APP(MyApp);
IMPLEMENT_APP_NO_MAIN(MyApp);
IMPLEMENT_WX_THEME_SUPPORT;
bool MyApp::OnInit()
{
MyFrame *frame = new MyFrame();
wxInitAllImageHandlers();
wxFileSystem::AddHandler( new wxMemoryFSHandler );
wxFileSystem::AddHandler( new wxInternetFSHandler );
HtmlWindow * htmlWindow = new HtmlWindow(frame);
htmlWindow->SetRelatedFrame(frame, "HTML");
htmlWindow->SetRelatedStatusBar(0);
wxString htmlFile = wxString("[FULL_PATH]/file.htm");
wxFileName htmlFileName(htmlFile);
htmlWindow->LoadFile(htmlFileName));
frame->Show(true);
return true;
}
作为一个实验,我用 SetPage 替换了 LoadFile,并在 wxFrame 中看到了内容:
htmlWindow->SetPage("<html><body>"
"<h1>TEST</h1>"
"Set Page Works"
"</body></hmtl>");
当我将 file.htm 放入浏览器时,我看到显示正常。由于某种原因,它不想在 wxFrame 中显示。如果我遗漏了什么,请告诉我。非常感谢所有帮助。
如果有人可以发布一个非常简单的 wxApp、wxFrame 和 wxWindow 代码,该代码只显示一个本地 htm 文件,那就太好了。我已经挣扎了这么久,它变得令人沮丧。