Thread: Problems with LoadBitmap()

  1. #1
    Funniest man in this seat minesweeper's Avatar
    Join Date
    Mar 2002
    Posts
    798

    Problems with LoadBitmap()

    Hi guys I am using Bloodshed Dev C++ 4 having real trouble with the LoadBitmap() function. I have been to the thread titled:

    C Board - Super-Newbie. Need to see how to use LoadBitmap() correctly?

    And consequently I have tried the following:

    1.
    This one didn’t compile giving a parse error on the lines beginning with HINSTANCE and hbmrocket.

    Source Code:

    Code:
    HBITMAP hbmrocket;
     
    
    
        switch(msg)
        {
        case WM_CREATE:
    {
       HINSTANCE hInstance = GetWindowLong(hwnd, GWL_HINSTANCE);
        hbmrocket = LoadBitmap(hInstance, "myBitmap");
    }
        break;
    //rest of code
    resource file:

    myBitmap BITMAP "C:/Games/civ2-tot/civ/Original/23imp.bmp"

    2.

    This one compiles but does not paint the bitmap or show the message box.

    Source code:

    Code:
    HBITMAP hbmrocket = NULL;
        switch(msg)
        {
        case WM_CREATE:
         {
    
        hbmrocket = LoadBitmap(GetModuleHandle(NULL),MAKEINTRESOURCE(IDD_ROCKET));
        if(hbmrocket == NULL)
                MessageBox(hwnd, "Could not load myBitmap!", "Error", MB_OK | MB_ICONEXCLAMATION);
            }
    resource file:

    IDD_ROCKET BITMAP "C:/Games/civ2-tot/civ/Original/65imp.bmp"
    myBitmap BITMAP "C:/Games/civ2-tot/civ/Original/65imp.bmp"

    and IDD_ROCKET is #defined correctly in a header file (it compiles so no error there).

    In both cases, my WM_PAINT case is as follows:

    Code:
    case WM_PAINT:
        {
            BITMAP bm;
            PAINTSTRUCT ps;
            HBITMAP hbmOld;
    
            HDC hdc = BeginPaint(hwnd, &ps);
    
            HDC hdcMem = CreateCompatibleDC(hdc);
            SelectObject(hdcMem, hbmrocket);
    
            GetObject(hbmrocket, sizeof(bm), &bm);
    
            BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);
    
            SelectObject(hdcMem, hbmOld);
            DeleteDC(hdcMem);
    
            EndPaint(hwnd, &ps);
        }
        break;
    Is anyone able to see what the problem is and give an answer? If so I would be most grateful.

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    LoadBitmap() or LoadImage() (the new version)
    only work on resource images included in the exe.

    "The LoadBitmap function loads the specified bitmap resource from a module's executable file. This function has been superseded by the LoadImage function. " MSDN help

    Add the bitmap to the resources as you would a dialog. It will not load from file like that.

    (Minor error may be typo)
    Also you are not catching the return from SelectObject() for the original (old) bitmap.

    hbmOld=SelectObject(hdcMem, hbmrocket);
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    Funniest man in this seat minesweeper's Avatar
    Join Date
    Mar 2002
    Posts
    798
    I did originally use the line:

    hbmOld=SelectObject(hdcMem, hbmrocket);

    But it wouldn't compile, instead it gave me an error saying that ANSI C++ forbids conversion from (void *) in assignment or something similar.

    Have you come across this problem?

  4. #4
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Originally posted by minesweeper
    I did originally use the line:

    hbmOld=SelectObject(hdcMem, hbmrocket);

    But it wouldn't compile, instead it gave me an error saying that ANSI C++ forbids conversion from (void *) in assignment or something similar.

    Have you come across this problem?
    Yup......here

  5. #5
    Funniest man in this seat minesweeper's Avatar
    Join Date
    Mar 2002
    Posts
    798
    Ok I type casted the return from SelectObject() ok, that was great thanks.

    My next question is about adding the Bitmap to the resource as i would a dialog. I have added dialogs so i know the routine but when it comes to using bitmaps I have used the toolbar button and dialog box as provided by Bloodshed's DevC++ software. That is why i was using the filepath approach.

    Can you give me some pointers as to how to add the bitmap to the resource in the way that you suggest? Not actual code as i want to learn for future use but i admit that so far i have used standard compiler functions and I don't know any other way.

    Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. No clue how to make a code to solve problems!
    By ctnzn in forum C Programming
    Replies: 8
    Last Post: 10-16-2008, 02:59 AM
  2. String Manipulation problems -_-
    By Astra in forum C Programming
    Replies: 5
    Last Post: 12-13-2006, 05:48 PM
  3. Rendering problems (DirectX?)
    By OnionKnight in forum Tech Board
    Replies: 0
    Last Post: 08-17-2006, 12:17 PM
  4. contest problems on my site
    By DavidP in forum Contests Board
    Replies: 4
    Last Post: 01-10-2004, 09:19 PM
  5. DJGPP problems
    By stormswift in forum C Programming
    Replies: 2
    Last Post: 02-26-2002, 04:35 PM