OLE with wxWidgets


/************************************************************************
 * Description: wxWidgets 之 OLE 学习
 * Author: Bill Adams
 * 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
 ************************************************************************/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Bill Adams

喜欢?打赏一杯阔乐吧!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值