在exe程序中嵌入图片

1、利用Bin2C将图片转换成“*.c”文件;

2、包含“*.c”文件,具体代码如下:

        =====文件名:PNG_ICON_BGMain.cpp=====
/***************************************************************
 * Name:      PNG_ICON_BGMain.cpp
 * Purpose:   Code for Application Frame
 * Author:    emonkey (dqifa@163.com)
 * Created:   2012-10-20
 * Copyright: emonkey ()
 * License:
 **************************************************************/

#include "PNG_ICON_BGMain.h"
#include <wx/msgdlg.h>

//(*InternalHeaders(PNG_ICON_BGFrame)
#include <wx/intl.h>
#include <wx/string.h>
//*)
//添加相关头文件
#include <wx/dcclient.h>
#include <wx/mstream.h>
#include "icon.c"
//helper functions
enum wxbuildinfoformat {
    short_f, long_f };

wxString wxbuildinfo(wxbuildinfoformat format)
{
    wxString wxbuild(wxVERSION_STRING);

    if (format == long_f )
    {
#if defined(__WXMSW__)
        wxbuild << _T("-Windows");
#elif defined(__UNIX__)
        wxbuild << _T("-Linux");
#endif

#if wxUSE_UNICODE
        wxbuild << _T("-Unicode build");
#else
        wxbuild << _T("-ANSI build");
#endif // wxUSE_UNICODE
    }

    return wxbuild;
}

//(*IdInit(PNG_ICON_BGFrame)
const long PNG_ICON_BGFrame::idMenuQuit = wxNewId();
const long PNG_ICON_BGFrame::idMenuAbout = wxNewId();
const long PNG_ICON_BGFrame::ID_STATUSBAR1 = wxNewId();
//*)

BEGIN_EVENT_TABLE(PNG_ICON_BGFrame,wxFrame)
    //(*EventTable(PNG_ICON_BGFrame)
    //*)
END_EVENT_TABLE()

PNG_ICON_BGFrame::PNG_ICON_BGFrame(wxWindow* parent,wxWindowID id)
{
    //(*Initialize(PNG_ICON_BGFrame)
    wxMenuItem* MenuItem2;
    wxMenuItem* MenuItem1;
    wxMenu* Menu1;
    wxMenuBar* MenuBar1;
    wxMenu* Menu2;

    Create(parent, id, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, _T("id"));
    SetClientSize(wxSize(400,277));
    MenuBar1 = new wxMenuBar();
    Menu1 = new wxMenu();
    MenuItem1 = new wxMenuItem(Menu1, idMenuQuit, _("Quit\tAlt-F4"), _("Quit the application"), wxITEM_NORMAL);
    Menu1->Append(MenuItem1);
    MenuBar1->Append(Menu1, _("&File"));
    Menu2 = new wxMenu();
    MenuItem2 = new wxMenuItem(Menu2, idMenuAbout, _("About\tF1"), _("Show info about this application"), wxITEM_NORMAL);
    Menu2->Append(MenuItem2);
    MenuBar1->Append(Menu2, _("Help"));
    SetMenuBar(MenuBar1);
    StatusBar1 = new wxStatusBar(this, ID_STATUSBAR1, 0, _T("ID_STATUSBAR1"));
    int __wxStatusBarWidths_1[1] = { -1 };
    int __wxStatusBarStyles_1[1] = { wxSB_NORMAL };
    StatusBar1->SetFieldsCount(1,__wxStatusBarWidths_1);
    StatusBar1->SetStatusStyles(1,__wxStatusBarStyles_1);
    SetStatusBar(StatusBar1);
    Center();

    Connect(idMenuQuit,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&PNG_ICON_BGFrame::OnQuit);
    Connect(idMenuAbout,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&PNG_ICON_BGFrame::OnAbout);
    Connect(wxEVT_PAINT,(wxObjectEventFunction)&PNG_ICON_BGFrame::OnPaint);
    //*)
    //添加图标
        wxIcon FrameIcon;
        wxMemoryInputStream istream(acicon, sizeof acicon);
//        FrameIcon.CopyFromBitmap(wxBitmap(wxImage(_T("C:\\Users\\Administrator\\Desktop\\TT\\TT.png"))));
//        wxBitmap BackgroundBitmap(istream,wxBITMAP_TYPE_PNG);
        FrameIcon.CopyFromBitmap(wxBitmap(wxImage(istream,wxBITMAP_TYPE_PNG)));
        SetIcon(FrameIcon);
}

PNG_ICON_BGFrame::~PNG_ICON_BGFrame()
{
    //(*Destroy(PNG_ICON_BGFrame)
    //*)
}

void PNG_ICON_BGFrame::OnQuit(wxCommandEvent& event)
{
    Close();
}

void PNG_ICON_BGFrame::OnAbout(wxCommandEvent& event)
{
    wxString msg = wxbuildinfo(long_f);
    wxMessageBox(msg, _("Welcome to..."));
}

void PNG_ICON_BGFrame::OnPaint(wxPaintEvent& event)
{
    //绘制背景图片
    wxMemoryInputStream istream(acicon, sizeof acicon);
//    wxImage myimage_img(istream, wxBITMAP_TYPE_PNG);
//    wxBitmap BackgroundBitmap;
    wxBitmap BackgroundBitmap(istream,wxBITMAP_TYPE_PNG);
    wxPaintDC dc(this);
    dc.DrawBitmap(BackgroundBitmap, 0, 0);
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值