Loading Resource Bitmaps

This is a discussion on Loading Resource Bitmaps within the Windows Programming forums, part of the Platform Specific Boards category; I am sick and tired of giving out my windows applications with bitmap files that are required. Does anyone know ...

  1. #1
    Intranasal Heroin User Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,035

    Loading Resource Bitmaps

    I am sick and tired of giving out my windows applications with bitmap files that are required. Does anyone know how to use a resource bitmap? Thanks in advance.

  2. #2
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Lightbulb I have something that might help!

    I know of some things you need:

    in your resource file, put:

    402 BITMAP "Bmp location"

    Then, in your main code:

    HBITMAP hBmp;

    case WM_CREATE:

    hBmp=LoadBitmap(Program's Instance, MAKEINTRESOURCE(402));

    break;

    The only thing I don't know how to do is use WM_PAINT to draw the Bitmap. This is as far as I've gotten. I hope I helped some.
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: trifaze_mattu@lycos.com

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  3. #3
    Intranasal Heroin User Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,035
    thanks! now all need to know how to do is draw the bitmap.

  4. #4
    Registered User The15th's Avatar
    Join Date
    Aug 2001
    Posts
    125
    WM_CREATE:
    hInstance = ((LPCREATESTRUCT) lParam)->hInstance ;
    hBitmap = LoadBitmap (hInstance, TEXT ("BITMAP")) ;
    GetObject (hBitmap, sizeof (BITMAP), &bitmap) ;
    cxSource = bitmap.bmWidth ;
    cySource = bitmap.bmHeight ;

    WM_PAINT:
    hdcMem = CreateCompatibleDC (hdc) ;
    SelectObject (hdcMem, hBitmap) ;
    BitBlt (hdc, 1, 1, 50, 50, hdcMem, 0, 0, SRCCOPY)

    wm_destroy
    DeleteObject (hBitmap) ;

    wm_size
    cxClient = LOWORD (lParam) ;
    cyClient = HIWORD (lParam) ;

    i think that will work.
    arrh, i got nothing good to say.
    http://www.praxis1.vic.edu.au/home/dcola/

  5. #5
    Intranasal Heroin User Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,035
    thanks, but that doesn't work.

  6. #6
    Registered User The15th's Avatar
    Join Date
    Aug 2001
    Posts
    125
    i chucked this code up in a hurry so i just went and check it to see if it works. and it worked fine for me. There is a few reasons i can guess why it wont be working. if it compiled okay then im guession when you named your bitmap you didnt name it "mybitmap" or "thepic" or whatever, but include it inside "" marks in the resource script. also when you call hBitmap = LoadBitmap (hInstance, TEXT ("BITMAP")) ; make sure you call
    TEXT ("mypic or whatever you called it"))
    arrh, i got nothing good to say.
    http://www.praxis1.vic.edu.au/home/dcola/

  7. #7
    Intranasal Heroin User Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,035
    no, I don't think that's it. My compiler doesn't like anything in WM_SIZE or some stuff in wm_create

  8. #8
    Intranasal Heroin User Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,035
    here are my errors:
    Code:
    Compiling...
    main.cpp
    C:\Tom\GameWIN\EDUWIN\main.cpp(14) : error C2065: 'hInstance' : undeclared identifier
    C:\Tom\GameWIN\EDUWIN\main.cpp(14) : error C2065: 'lParam' : undeclared identifier
    C:\Tom\GameWIN\EDUWIN\main.cpp(14) : error C2440: '=' : cannot convert from 'struct HINSTANCE__ *' to 'int'
            This conversion requires a reinterpret_cast, a C-style cast or function-style cast
    C:\Tom\GameWIN\EDUWIN\main.cpp(15) : error C2065: 'hBitmap' : undeclared identifier
    C:\Tom\GameWIN\EDUWIN\main.cpp(16) : error C2065: 'bitmap' : undeclared identifier
    C:\Tom\GameWIN\EDUWIN\main.cpp(17) : error C2065: 'cxSource' : undeclared identifier
    C:\Tom\GameWIN\EDUWIN\main.cpp(17) : error C2228: left of '.bmWidth' must have class/struct/union type
    C:\Tom\GameWIN\EDUWIN\main.cpp(18) : error C2065: 'cySource' : undeclared identifier
    C:\Tom\GameWIN\EDUWIN\main.cpp(18) : error C2228: left of '.bmHeight' must have class/struct/union type
    C:\Tom\GameWIN\EDUWIN\main.cpp(25) : error C2065: 'hdcMem' : undeclared identifier
    C:\Tom\GameWIN\EDUWIN\main.cpp(25) : error C2440: '=' : cannot convert from 'struct HDC__ *' to 'int'
            This conversion requires a reinterpret_cast, a C-style cast or function-style cast
    C:\Tom\GameWIN\EDUWIN\main.cpp(28) : error C2146: syntax error : missing ';' before identifier 'EndPaint'
    C:\Tom\GameWIN\EDUWIN\main.cpp(40) : error C2065: 'cxClient' : undeclared identifier
    C:\Tom\GameWIN\EDUWIN\main.cpp(41) : error C2065: 'cyClient' : undeclared identifier
    help please? thanks.

  9. #9
    Registered User The15th's Avatar
    Join Date
    Aug 2001
    Posts
    125
    omg... *BASIC* programming rules, any varable used must be declared first...

    static HBITMAP hBitmap ;
    static int cxClient, cyClient, cxSource, cySource;
    BITMAP bitmap ;
    HDC hdc, hdcMem ;
    HINSTANCE hInstance ;
    PAINTSTRUCT ps;

    i think that is all of them, if not just declare them.
    arrh, i got nothing good to say.
    http://www.praxis1.vic.edu.au/home/dcola/

  10. #10
    Intranasal Heroin User Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,035
    Sorry, I just figured that out, but it still won't show! It compiles, though.

  11. #11
    Intranasal Heroin User Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,035
    I DID IT!!!!!!!!!!!!!! yaaaahoooooooooooooo! Sept i didn't use TEXT(), I used MAKEINTRESOURCE(). Thanks for showing me how to draw!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Loading an image in from a resource file
    By starcatcher in forum C++ Programming
    Replies: 4
    Last Post: 04-15-2008, 07:44 AM
  2. Loading a bitmap (Without using glaux)
    By Shamino in forum Game Programming
    Replies: 7
    Last Post: 03-16-2006, 09:43 AM
  3. Problem Loading Bitmaps in Allegro
    By LiNeAr in forum Game Programming
    Replies: 1
    Last Post: 08-15-2005, 05:12 PM
  4. Loading a Bitmap resource for OpenGL Texture[x]
    By the dead tree in forum Game Programming
    Replies: 4
    Last Post: 08-26-2004, 02:12 PM
  5. Loading bitmaps with createfile() +CreateDIBSection
    By Stevo in forum Windows Programming
    Replies: 7
    Last Post: 05-13-2004, 10:22 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21