在exe程序中嵌入图片 博客分类: wxwidgets编程 Bin2C嵌入图片
程序员文章站
2024-03-25 21:01:58
...
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); }