So here's the deal: I'm trying to load a few bitmaps from within my program's executable, i.e. without loading them from outside files. I looked around for a while for a simple way to do this, and the simplest way seems to be with XPM files. I converted the bitmaps to XPM and included them in my code, but then I realized... I have no idea what to do with it.
It seems to just define a static char array, with information on the colors and whatnot. So how can I convert it into a bitmap within my program?
The code for the XPM files looks a bit like this:
static char *SQUARE_xpm[]={
"180 180 2 1",
" c #FF00FF",
"0 c #FFFFFF",
What's wrong for you to include those bitmaps as resources and then just call LoadBitmap API?
Hundreds of unclear and contradictory explanations on how to do so. If you could help explain it I'd be grateful. Honestly, either way works. I've never used resource files before.
Hundreds of unclear and contradictory explanations on how to do so. If you could help explain it I'd be grateful. Honestly, either way works. I've never used resource files before.
Well, I never used XPM files and have no idea why I could have to use them....
As for the resources... You've posted to the forum:
Visual C++ Programming Ask questions about Windows programming with Visual C++ and help others by answering their questions.
so I presume you are using some of the Microsoft IDE (such as VC++6.0, VS2003, VS2005, VS2008, VS2010) to create your applications. Doesn't the IDE you are currently using have a resourced editor?
Yes, I'm using VC++ 2010 Express. I just haven't been able to find anything to explain exactly what I'm looking for. I just want a bitmap embedded in my program's executable at compile time, that I can access from within the program. Whenever I try to find an explanation on how to do this, I always come up with a tutorial on importing cursors or icons for windows form applications (which my program isn't).
Of course, I'm probably missing something. I just can't seem to find a straight answer anywhere.
Unfortunately, Express editions of Visual Studio don’t have Resource Editors.
However, you can manually edit your .rc file. Just add:
Code:
IDB_YOUR_ID BITMAP "res\\your_file_name.bmp"
line to it, and define that ID somewhere in your resource.h file (create it if your project doesn’t have it).
Then you can use LoadBitmap() function as Victor suggested above.
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio: FeinViewer - an integrated GDI objects viewer for Visual C++ Debugger, and more...
and included it under "resources" in my project, then created a resource.h file. I assume this will make my project include the resource files in the executable at compile time. But how do I define these resources in resource.h? Does the .rc file have to be #included by resource.h? What is the scope of the LoadBitmap() function?
and included it under "resources" in my project, then created a resource.h file. I assume this will make my project include the resource files in the executable at compile time. But how do I define these resources in resource.h? Does the .rc file have to be #included by resource.h? What is the scope of the LoadBitmap() function?
Yes, you should place
Code:
#include "resource.h"
at the top of your rc file, and wherever you call LoadBitmap() from.
In the resource.h you should have something like that:
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio: FeinViewer - an integrated GDI objects viewer for Visual C++ Debugger, and more...
By "scope" I meant where does the LoadBitmap() function have to be called from, but I figured it out. It seems to be from windows.h...
#including reseource.h in the .rc file causes problems, so I assume you meant the opposite. But now that I've defined the IDs as 101 and 102... how do I use them with the LoadBitmap function? What does the function return?
Bookmarks