-
July 15th, 2011, 04:44 AM
#1
Loading a bitmap in-code with XPM file
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",
<pixel information>
};
-
July 15th, 2011, 05:26 AM
#2
Re: Loading a bitmap in-code with XPM file
What's wrong for you to include those bitmaps as resources and then just call LoadBitmap API?
Victor Nijegorodov
-
July 15th, 2011, 05:33 AM
#3
Re: Loading a bitmap in-code with XPM file
Originally Posted by VictorN
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.
-
July 15th, 2011, 05:41 AM
#4
Re: Loading a bitmap in-code with XPM file
Originally Posted by Gatleos
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?
Victor Nijegorodov
-
July 15th, 2011, 03:11 PM
#5
Re: Loading a bitmap in-code with XPM file
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.
-
July 15th, 2011, 03:41 PM
#6
Re: Loading a bitmap in-code with XPM file
Originally Posted by Gatleos
Yes, I'm using VC++ 2010 Express...
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:
FeinWindows - replacement windows manager for Visual Studio, and more...
-
July 15th, 2011, 04:06 PM
#7
Re: Loading a bitmap in-code with XPM file
Yeah, I thought I read somewhere that VC++ Express doesn't have a resource editor.
So... how exactly do I define a resource ID? I've created a .rc file containing this:
IDB_ASCII_SQUARE BITMAP "Art\CURSES_SQUARE.bmp"
IDB_ASCII_TERMINAL BITMAP "ART\CURSES_TERMINAL.bmp"
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?
Thanks for the help so far.
-
July 15th, 2011, 04:30 PM
#8
Re: Loading a bitmap in-code with XPM file
Originally Posted by Gatleos
So... how exactly do I define a resource ID? I've created a .rc file containing this:
IDB_ASCII_SQUARE BITMAP "Art\CURSES_SQUARE.bmp"
IDB_ASCII_TERMINAL BITMAP "ART\CURSES_TERMINAL.bmp"
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:
Code:
#define IDB_ASCII_SQUARE 101
#define IDB_ASCII_TERMINAL 102
Don't understand your "scope" question.
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
-
July 15th, 2011, 05:02 PM
#9
Re: Loading a bitmap in-code with XPM file
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?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|