wxWidgets access html file in zip package

/************************************************************************
* Description: 访问zip中的htm 之 Widgets学习
* Author: 陈相礼
* Compiled: VC8 + wxWidgets2.8.10
* Date: 04/02/10
************************************************************************/
/************************************************************************ * Description: 访问zip中的htm 之 Widgets学习 * Author: 陈相礼 * Compiled: VC8 + wxWidgets2.8.10 * Date: 04/02/10 ************************************************************************/ #include "wx/wx.h" #include "wx/image.h" #include "wx/html/htmlwin.h" #include "wx/fs_zip.h" class AppMain : public wxApp { public: virtual bool OnInit(); protected: private: }; class FrameMain : public wxFrame { public: FrameMain( const wxString& title, const wxPoint& pos, const wxSize& size ); void OnQuit( wxCommandEvent& event ); void OnBack( wxCommandEvent& event ); void OnForward( wxCommandEvent& event); protected: private: DECLARE_EVENT_TABLE() }; enum { // 菜单ID Minimal_Quit = 1, Minimal_Back, Minimal_Forward, }; // 事件表 BEGIN_EVENT_TABLE( FrameMain, wxFrame ) EVT_MENU( Minimal_Quit, FrameMain::OnQuit ) EVT_MENU( Minimal_Back, FrameMain::OnBack ) EVT_MENU( Minimal_Forward, FrameMain::OnForward ) END_EVENT_TABLE() // 指定入口类 IMPLEMENT_APP( AppMain ) // 入口开始点 bool AppMain::OnInit() { wxImage::AddHandler(new wxPNGHandler); wxImage::AddHandler(new wxJPEGHandler); wxFileSystem::AddHandler(new wxZipFSHandler); FrameMain *frame = new FrameMain( wxT("Zip and Html测试"), wxDefaultPosition, wxSize( 1024, 768 ) ); frame->Show( true ); SetTopWindow( frame ); return true; } wxHtmlWindow *html = NULL; FrameMain::FrameMain( const wxString& title, const wxPoint& pos, const wxSize& size ) : wxFrame( (wxFrame *)NULL, wxID_ANY, title, pos, size ) { wxMenu *menuFile = new wxMenu; wxMenu *menuNavi = new wxMenu; // 创建菜单 menuFile->Append( Minimal_Quit, wxT("退出(&E)") ); menuNavi->Append( Minimal_Back, wxT("后退(&B)") ); menuNavi->Append( Minimal_Forward, wxT("向前(&F)") ); wxMenuBar *menuBar = new wxMenuBar; menuBar->Append( menuFile, wxT("文件(&F)") ); menuBar->Append( menuNavi, wxT("导航(&N)") ); // 挂载菜单 SetMenuBar( menuBar ); // 设定状态栏 CreateStatusBar( 2 ); html = new wxHtmlWindow( this ); html->SetRelatedFrame( this, wxT("HTML:%s") ); html->SetRelatedStatusBar( 0 ); html->LoadPage( wxT("start.htm") ); } //---------------------------------------------------------------------- // 退出 void FrameMain::OnQuit( wxCommandEvent& WXUNUSED(event) ) { Close( true ); } //---------------------------------------------------------------------- // 后退 void FrameMain::OnBack( wxCommandEvent& WXUNUSED(event) ) { if ( !html->HistoryBack() ) { wxMessageBox( wxT("这是最后一条历史记录了~~~") ); } } //---------------------------------------------------------------------- // 前进 void FrameMain::OnForward( wxCommandEvent& WXUNUSED(event) ) { if ( !html->HistoryForward() ) { wxMessageBox( wxT("没有更多历史记录了~~~") ); } } /************************************************************************ 附:start.htm源码 <html><body> <h1>ZIP archive</h1> <h3>feature demo</h3> <p> Click on this <a href="pages.zip#zip:test.htm" mce_href="pages.zip#zip:test.htm">link</a> to load page stored in ZIP archive (<a href="pages.zip" mce_href="pages.zip">pages.zip</a>). Enjoy it! </body></html> 依赖: wxmsw28ud_html.lib wxmsw28ud_core.lib wxbase28ud.lib wxtiffd.lib wxjpegd.lib wxpngd.lib wxzlibd.lib wxregexud.lib wxexpatd.lib winmm.lib comctl32.lib rpcrt4.lib wsock32.lib odbc32.lib ************************************************************************/

你可能感兴趣的:(wxWidgets access html file in zip package)