OLE with wxWidgets

* Description:    wxWidgets 之 OLE 学习
* Author:        陈相礼
* Compiled:        VC8 + wxWidgets2.8.10
* Date:            04/02/10

/************************************************************************ * Description: wxWidgets 之 OLE 学习 * Author: 陈相礼 * Compiled: VC8 + wxWidgets2.8.10 * Date: 04/02/10 ************************************************************************/ #include "wx/wx.h" #include "wx/msw/ole/automtn.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 OnAbout( wxCommandEvent& event ); void OnTest( wxCommandEvent& event); protected: private: DECLARE_EVENT_TABLE() }; enum { // 菜单ID OleAuto_Quit = 1, OleAuto_About, OleAuto_Test, // 控件ID OleAuto_Text = 1000 }; // 事件表 BEGIN_EVENT_TABLE( FrameMain, wxFrame ) EVT_MENU(OleAuto_Quit, FrameMain::OnQuit) EVT_MENU(OleAuto_About, FrameMain::OnAbout) EVT_MENU(OleAuto_Test, FrameMain::OnTest) END_EVENT_TABLE() // 指定入口类 IMPLEMENT_APP( AppMain ) // 入口开始点 bool AppMain::OnInit() { FrameMain *frame = new FrameMain( wxT("OleAuto wxWidgets 测试"), wxPoint(50, 50), wxSize(450, 340) ); frame->Show( true ); SetTopWindow( frame ); return true; } FrameMain::FrameMain( const wxString& title, const wxPoint& pos, const wxSize& size ) : wxFrame( (wxFrame *)NULL, wxID_ANY, title, pos, size ) { // 创建菜单栏 wxMenu *menuFile = new wxMenu; menuFile->Append( OleAuto_Test, wxT("Excel Automation 测试(&T)") ); menuFile->Append( OleAuto_About, wxT("关于(&A)") ); menuFile->AppendSeparator(); menuFile->Append( OleAuto_Quit, wxT("退出(&E)") ); wxMenuBar *menuBar = new wxMenuBar; menuBar->Append( menuFile, wxT("文件(&F)") ); SetMenuBar( menuBar ); CreateStatusBar( 2 ); SetStatusText( wxT("OLE Demo!") ); } //---------------------------------------------------------------------- // 退出 void FrameMain::OnQuit( wxCommandEvent& WXUNUSED(event) ) { Close( true ); } //---------------------------------------------------------------------- // 后退 void FrameMain::OnAbout( wxCommandEvent& WXUNUSED(event) ) { wxMessageBox( wxT("这是一个OLE Automation 实例"), wxT("关于 OleAuto"), wxOK | wxICON_INFORMATION, this ); } //---------------------------------------------------------------------- // 前进 void FrameMain::OnTest( wxCommandEvent& WXUNUSED(event) ) { wxMessageBox( wxT("确保你的Excel已经运行, 然后点击 确定./n激活的单元格将会以粗体显示 'wxWidgets automation test!' .")); wxAutomationObject excelObject, rangeObject; if (!excelObject.GetInstance(wxT("Excel.Application"))) { if (!excelObject.CreateInstance(wxT("Excel.Application"))) { wxMessageBox(wxT("无法创建 Excel 对象.")); return; } } if (!excelObject.PutProperty(wxT("ActiveCell.Value"), wxT("wxWidgets automation test!"))) { wxMessageBox(wxT("无法激活单元格.")); return; } if (!excelObject.PutProperty(wxT("ActiveCell.Font.Bold"), wxVariant(true)) ) { wxMessageBox(wxT("单元格无法设置粗体属性.")); return; } } /************************************************************************ 附:依赖 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 ************************************************************************/

你可能感兴趣的:(Date,测试,Excel,table,Class,menu)