【发布时间】:2018-08-10 04:11:34
【问题描述】:
我一直在尝试用一个带有图片的按钮制作一个简单的 wxWidgets 程序。我已经能够很容易地制作带有图像的按钮,但是在包含它时出现了我的问题。
到目前为止,我只能在运行时获取图像(图像必须与 .exe 文件位于同一文件夹中;否则,我会收到错误 2:系统找不到指定的文件)。使用这种方法,我没有任何问题——程序运行良好。然而,我想要做的是#include 文件,以便它在编译时嵌入,因此它不需要在运行时可用。
我尝试过#include 文件(包括 .png 和 .xpm),我还尝试将其添加到资源包含中(这是在 Visual Studio 2017 上)。这两种方法都不起作用——第一种方法仍然要求图像在同一个文件夹中,第二种方法在编译过程中失败(据我所知,它无法读取 .xpm 文件)。
这里是相关代码,如果有帮助的话:
/*relevant includes*/
#include "happyFace.png" //this isn't working. the file is still needed
||
#include "happyFace.xpm" //ditto
/*I have also tried putting these lines in the resource includes.*/
/*code*/
wxInitAllImageHandlers();
wxBitmap bitmap("happyFace.xpm", wxBITMAP_TYPE_XPM); //only works in same directory at run-time
||
wxBitmap bitmap("happyFace.png", wxBITMAP_TYPE_PNG); //ditto
wxButton *button = new wxButton(this, ID_BMP_BUTTON);
button->SetBitmap(bitmap);
//the rest of the button programming and stuff
抱歉,如果我没有提供足够的信息;如果需要,我可以提供更多。我真的很感激任何帮助。谢谢!
【问题讨论】:
标签: c++ visual-c++ runtime wxwidgets compile-time