Displaying Two BitMaps

This is a discussion on Displaying Two BitMaps within the Windows Programming forums, part of the Platform Specific Boards category; I want to display two bitmap files one on top of the other. The ball then the dot on top ...

  1. #1
    Registered User kryptkat's Avatar
    Join Date
    Dec 2002
    Posts
    638

    Smile Displaying Two BitMaps

    I want to display two bitmap files one on top of the other. The ball then the dot on top but not mixed with ball. I want to move the dot over the ball. Prog is in c.

    The problem is that it will only display one bitmap and not the dot bitmap. What did I miss or overlook? Each structor is defined loaded resourced and

    HBITMAP g_hbmBall = NULL; //hbm ball defined as hbitmap check
    HBITMAP g_hbmDot = NULL; //hbm dot defined as hbitmap check

    // more code

    g_hbmBall = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BALL));
    g_hbmDot = LoadBitmap(GetModuleHandle(NULL),MAKEINTRESOURCE(I DB_DOT));

    // ball and dot loadedbitmap check

    case wm_paint{

    BITMAP bm;
    PAINTSTRUCT ps;



    HDC hdc = BeginPaint(hwnd, &ps);

    HDC hdcMem = CreateCompatibleDC(hdc);
    HBITMAP hbmOld = SelectObject(hdcMem, g_hbmBall);
    BITMAP bm2;
    PAINTSTRUCT ps2;

    HDC hdc2 = BeginPaint(hwnd, &ps2);

    HDC hdcMem2 = CreateCompatibleDC(hdc2);
    HBITMAP hbmOld2 = SelectObject(hdcMem2, g_hbmDot);

    // hdc and dc and mem both created check



    GetObject(g_hbmBall, sizeof(bm), &bm);

    BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);

    SelectObject(hdcMem, hbmOld);
    DeleteDC(hdcMem);
    EndPaint(hwnd, &ps);



    /* insert dot */
    /* BITMAP bm2; */
    /* PAINTSTRUCT ps2; */

    /* HDC hdc2 = BeginPaint(hwnd, &ps2); */

    /* HDC hdcMem2 = CreateCompatibleDC(hdc2); */
    /* HBITMAP hbmOld2 = SelectObject(hdcMem2, g_hbmDot); */

    /* bm2 and ps2 moved up because of compile error declaration is not allowed here in function windproc */
    GetObject(g_hbmDot, sizeof(bm2), &bm2);
    /* bm2 */

    BitBlt(hdc2,524, 224, bm2.bmWidth, bm2.bmHeight, hdcMem2, 0, 0, SRCCOPY);
    // dot moved to side of ball to see if it was over painting
    SelectObject(hdcMem2, hbmOld2);
    DeleteDC(hdcMem2);


    EndPaint(hwnd, &ps2);
    }


    Last edited by kryptkat on 12-23-2002 at 05:04 PM

    I spent all morning yesterday with this to see if I could get it to work with no results. It compiles with no errors but only displays one bitmap. Then I spent the rest of the day reading everything I could find on BitBlt. It seems no one ever tryed this before lol.
    I did find one function that lets you or two bitmaps but that is not what I want. Yet anyway. Thank You in advance.

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Do not call BeginPaint two times. Instead make 2 compatible DC's and store one bitmap in each. Then just blt from the compatible DC to the main DC and you should be fine.

  3. #3
    Registered User kryptkat's Avatar
    Join Date
    Dec 2002
    Posts
    638

    Smile Thank You

    Thank You! It works!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Drawing bitmaps efficiently
    By scwizzo in forum Windows Programming
    Replies: 28
    Last Post: 06-30-2009, 08:25 PM
  2. DX9 Not Displaying Bitmaps
    By Sentral in forum Game Programming
    Replies: 9
    Last Post: 01-31-2006, 04:35 AM
  3. Problem displaying bitmaps
    By batman123 in forum Game Programming
    Replies: 2
    Last Post: 01-09-2005, 01:01 AM
  4. Bitmaps Not Displaying
    By DCII764II00 in forum Windows Programming
    Replies: 3
    Last Post: 05-25-2004, 03:14 PM
  5. Displaying bitmaps on a dialog
    By minesweeper in forum Windows Programming
    Replies: 2
    Last Post: 05-15-2002, 03:11 PM

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