X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/96ed08f775635ccf57ef797008b05427dfaabcc3..e946566e73a57c20de8705732638ee78bfb87a33:/samples/oleauto/oleauto.cpp diff --git a/samples/oleauto/oleauto.cpp b/samples/oleauto/oleauto.cpp index 9d1fe96853..f803eaf7c0 100644 --- a/samples/oleauto/oleauto.cpp +++ b/samples/oleauto/oleauto.cpp @@ -30,7 +30,7 @@ #include "wx/wx.h" #endif -#include +#include "wx/msw/ole/automtn.h" #ifndef __WXMSW__ #error "Sorry, this sample works under Windows only." @@ -91,7 +91,7 @@ enum OleAuto_Test, // controls start here (the numbers are, of course, arbitrary) - OleAuto_Text = 1000, + OleAuto_Text = 1000 }; // ---------------------------------------------------------------------------- @@ -125,6 +125,9 @@ IMPLEMENT_APP(MyApp) // `Main program' equivalent: the program execution "starts" here bool MyApp::OnInit() { + if ( !wxApp::OnInit() ) + return false; + // Create the main application window MyFrame *frame = new MyFrame(_T("OleAuto wxWidgets App"), wxPoint(50, 50), wxSize(450, 340)); @@ -198,12 +201,36 @@ void MyFrame::OnTest(wxCommandEvent& WXUNUSED(event)) wxAutomationObject excelObject, rangeObject; if (!excelObject.GetInstance(_T("Excel.Application"))) { + // Start Excel if it is not running if (!excelObject.CreateInstance(_T("Excel.Application"))) { wxMessageBox(_T("Could not create Excel object.")); return; } } + + // Ensure that Excel is visible + if (!excelObject.PutProperty(_T("Visible"), true)) + { + wxMessageBox(_T("Could not make Excel object visible")); + } + const wxVariant workbooksCountVariant = excelObject.GetProperty(_T("Workbooks.Count")); + if (workbooksCountVariant.IsNull()) + { + wxMessageBox(_T("Could not get workbooks count")); + return; + } + const long workbooksCount = workbooksCountVariant; + if (workbooksCount == 0) + { + const wxVariant workbook = excelObject.CallMethod(_T("Workbooks.Add")); + if (workbook.IsNull()) + { + wxMessageBox(_T("Could not create new Workbook")); + return; + } + } + if (!excelObject.PutProperty(_T("ActiveCell.Value"), _T("wxWidgets automation test!"))) { wxMessageBox(_T("Could not set active cell value.")); @@ -215,4 +242,3 @@ void MyFrame::OnTest(wxCommandEvent& WXUNUSED(event)) return; } } -