/************************************************************************ * Description: HtmlWidgets学习 * Author: 陈相礼 * Compiled: VC8 + wxWidgets2.8.10 * Date: 04/02/10 ************************************************************************/
/************************************************************************ * Description: HtmlWidgets学习 * Author: 陈相礼 * Compiled: VC8 + wxWidgets2.8.10 * Date: 04/02/10 ************************************************************************/ #include "wx/wx.h" #include "wx/html/htmlwin.h" #include "wx/html/m_templ.h" /************************************************************************/ /* 绑定、处理MYBIND标签中的内容。 */ TAG_HANDLER_BEGIN(MYBIND, "MYBIND") TAG_HANDLER_PROC(tag) { wxWindow *wnd; int ax, ay; int fl = 0; tag.ScanParam(wxT("X"), wxT("%i"), &ax); tag.ScanParam(wxT("Y"), wxT("%i"), &ay); if (tag.HasParam(wxT("FLOAT"))) fl = ax; wnd = new wxTextCtrl ( m_WParser->GetWindowInterface()->GetHTMLWindow(), wxID_ANY, tag.GetParam(wxT("NAME")), wxPoint(0,0), wxSize(ax, ay), wxTE_MULTILINE ); wnd->Show(true); m_WParser->GetContainer()->InsertCell(new wxHtmlWidgetCell(wnd, fl)); return false; } TAG_HANDLER_END(MYBIND) TAGS_MODULE_BEGIN(MyBind) TAGS_MODULE_ADD(MYBIND) TAGS_MODULE_END(MyBind) /************************************************************************/ 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, // 控件ID Minimal_Text = 1000 }; // 事件表 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() { FrameMain *frame = new FrameMain( wxT("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("wxHTML测试:'%s'") ); html->SetRelatedStatusBar( 1 ); 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> <head><title>Widgets demo</title></head> <body> <h3>wxHtmlWidgetCell demonstration</h3> There is binded window somewhere around. Enjoy it. <hr> <center> <mybind name="experimental binded window" x=300 y=500> </center> <hr> <mybind name="(small one)" x=150 y=30> <hr> <mybind name="a widget with floating width" float=y x="50" y=50> <hr> Here you can find multiple widgets at the same line:<br> here <mybind name="widget_1" x="100" y=30> ...and here: <mybind name="widget_2" x="150" y=30> </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 ************************************************************************/