Not loading bmp ?

This is a discussion on Not loading bmp ? within the Windows Programming forums, part of the Platform Specific Boards category; (Mingw - WinXP) I've been having trouble with this for awhile, it seems my program just refuses to load this ...

  1. #1
    60% Braindead
    Join Date
    Dec 2005
    Posts
    379

    Question Not loading bmp ?

    (Mingw - WinXP)
    I've been having trouble with this for awhile, it seems my program just refuses to load this .bmp file. I'm not sure if its a bad resource or bad code...

    Can anyone see why this doesnt load? (This is mostly the forgers tutorial with some adjustments.

    Code:
    //Resource.rc
    IDB_BALL                BITMAP  DISCARDABLE     "C:\\ball.bmp"
    Resource.rc compiled into Resource.o sucessfully.

    Code:
    //Rpg.cpp
    //Message loop, only part dealing with the bmp.
    
    // Included elsewhere #define IDB_BALL 1
    
     switch(msg) {
    
      case WM_CLOSE:
       DestroyWindow(hwnd);
       break;
    
      case WM_DESTROY:
       DeleteObject(ScreenDisplay_Object);
       PostQuitMessage(0);
       break;
    
      case WM_CREATE:
       ScreenDisplay_Object = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BALL));
       if(ScreenDisplay_Object == NULL)
        MessageBox(hwnd, "Could not load object!", "Error", MB_OK | MB_ICONEXCLAMATION);
       break;
    
      case WM_PAINT: {
       BITMAP bm;
       PAINTSTRUCT ps;
    
       HDC hdc = BeginPaint(hwnd, &ps); // 31
    
       HDC hdcMem = CreateCompatibleDC(hdc);
       HBITMAP hbmOld = (HBITMAP)SelectObject(hdcMem, ScreenDisplay_Object); //34
    
       GetObject(ScreenDisplay_Object, sizeof(bm), &bm);
    
       BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);
    
       SelectObject(hdcMem, hbmOld);
       DeleteDC(hdcMem);
     
       EndPaint(hwnd, &ps);
       }
       break;
    
      default:
       return DefWindowProc(hwnd, msg, wParam, lParam);
     }
    Rpg.cpp compiled into Rpg.o sucessfully

    Code:
    $ g++ -o C:/Rpg.exe C:\\Rpg.o C:\\Resource.o -mwindows
    Mingw compiles sucessfully, nothing goes wrong, but the bmp just doesnt load. Does anyone see why? >.>

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    The file exists . . . ?

    Maybe this should be moved to the Windows programming forum.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    60% Braindead
    Join Date
    Dec 2005
    Posts
    379
    No, it doesnt exit, it just bring up an error window (As it should) stating the bitmap was not loaded.

    Wasnt sure if it was a resource error or a code error, so I generalized it to being a C++ error hehe.

  4. #4
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Is there a getlasterror? I'm not sure, but 1 seems like a strange resource id.

    ╔╗╔╦══╦╗╔╦══╦╗
    ║╚╝║╔╗║╚╝║╔╗║║
    ║╔╗║╠╣║╔╗║╠╣╠╣
    ╚╝╚╩╝╚╩╝╚╩╝╚╩╝

    codez http://code.google.com/p/zxcvbn/

  5. #5
    60% Braindead
    Join Date
    Dec 2005
    Posts
    379
    I'm not sure how to check for the last error -,-.

    I changed the resource ID just to be sure (1 to 101). It still was unsucessful.

  6. #6
    Mad OnionKnight's Avatar
    Join Date
    Jan 2005
    Location
    Umeň, Sweden
    Posts
    555
    Quote Originally Posted by Blackroot
    I'm not sure how to check for the last error -,-.
    It's a function. As simple as DWORD GetLastError (void). However, if you want something more meaningful than a number you'd have to pass that value to FormatMessage, which is not as simple.
    http://msdn.microsoft.com/library/de...matmessage.asp

  7. #7
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >#define IDB_BALL 1
    Did you include this line in your Resource.rc?

  8. #8
    60% Braindead
    Join Date
    Dec 2005
    Posts
    379
    Lol! Good call swoopy, that was my problem, I didint realise you needed to define (Or could define) an object in the .rc file. Thanks .

  9. #9
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Blackroot, for your reference, I read it in the Forger's tutorial.
    Now what about this #include "resource.h" ? Well your program needs a way to identify the icon, and the best way to do that is to assign it a unique ID (IDI_MYICON). We can do this by creating the file "resource.h" and including it in both our resource script, and our source file.
    Here: http://www.winprog.org/tutorial/resources.html

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BMP Loading Structs
    By IdioticCreation in forum C++ Programming
    Replies: 4
    Last Post: 07-05-2007, 01:42 PM
  2. how come... (bmp loading)
    By Homunculus in forum Windows Programming
    Replies: 4
    Last Post: 03-21-2006, 09:00 PM
  3. OpenGL, loading BMP Textures?
    By Zeusbwr in forum Game Programming
    Replies: 12
    Last Post: 12-09-2004, 05:16 PM
  4. Loading BMP to a DirectDrawSurface
    By phatslug in forum Game Programming
    Replies: 1
    Last Post: 07-18-2002, 05:15 PM
  5. Loading BMP without WM_PAINT?
    By SyntaxBubble in forum Windows Programming
    Replies: 3
    Last Post: 01-10-2002, 10:59 PM

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