CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Hybrid View

  1. #1
    Join Date
    Jul 2011
    Posts
    5

    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>

    };

  2. #2
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    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

  3. #3
    Join Date
    Jul 2011
    Posts
    5

    Re: Loading a bitmap in-code with XPM file

    Quote Originally Posted by VictorN View Post
    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.

  4. #4
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Loading a bitmap in-code with XPM file

    Quote Originally Posted by Gatleos View Post
    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

  5. #5
    Join Date
    Jul 2011
    Posts
    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.

  6. #6
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: Loading a bitmap in-code with XPM file

    Quote Originally Posted by Gatleos View Post
    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...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured