Thread: Bitmaps Not Displaying

  1. #1
    Registered User DCII764II00's Avatar
    Join Date
    Dec 2003
    Posts
    7

    Bitmaps Not Displaying


    Hello All ^^
    Well I think I got used to resources, but.. I have a few problems left..

    Creating a resource for a bitmap image.. I would go through all the proper procedures for loading the bitmap. The program compiles with no errors, and yet.. The image fails to show up.. I am not sure why this occurs.. I will submit my source code and hopefully someone can aid me..

    Thank-You

    Farewell~
    DC




    Code:
    #include "stdafx.h"
    #include <windows.h>
    #include "resource.h"
    
    HINSTANCE hInst;
    LRESULT CALLBACK WindProcedure(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
    
    INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                       LPSTR lpCmdLine, int nCmdShow)
    {
        WNDCLASSEX  WndCls;
        static char szAppName[] = "BitmapIntro";
        MSG         Msg;
    
    	hInst       = hInstance;
        WndCls.cbSize        = sizeof(WndCls);
        WndCls.style         = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
        WndCls.lpfnWndProc   = WindProcedure;
        WndCls.cbClsExtra    = 0;
        WndCls.cbWndExtra    = 0;
        WndCls.hInstance     = hInst;
        WndCls.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
        WndCls.hCursor       = LoadCursor(NULL, IDC_ARROW);
        WndCls.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
        WndCls.lpszMenuName  = NULL;
        WndCls.lpszClassName = szAppName;
        WndCls.hIconSm       = LoadIcon(hInstance, IDI_APPLICATION);
        RegisterClassEx(&WndCls);
    
        CreateWindowEx(WS_EX_OVERLAPPEDWINDOW,
                              szAppName,
                              "Bitmaps Fundamentals",
                              WS_OVERLAPPEDWINDOW | WS_VISIBLE,
                              CW_USEDEFAULT,
                              CW_USEDEFAULT,
                              CW_USEDEFAULT,
                              CW_USEDEFAULT,
                              NULL,
                              NULL,
                              hInstance,
                              NULL);
    
        while( GetMessage(&Msg, NULL, 0, 0) )
        {
            TranslateMessage(&Msg);
            DispatchMessage( &Msg);
        }
    
        return static_cast<int>(Msg.wParam);
    }
    
    LRESULT CALLBACK WindProcedure(HWND hWnd, UINT Msg,
    			   WPARAM wParam, LPARAM lParam)
    {
        HDC hDC, MemDCExercising;
        PAINTSTRUCT Ps;
        HBITMAP bmpExercising;
    
        switch(Msg)
        {
    	case WM_DESTROY:
    	    PostQuitMessage(WM_QUIT);
    	    break;
    	case WM_PAINT:
    	    hDC = BeginPaint(hWnd, &Ps);
    
    	    // Load the bitmap from the resource
    	    bmpExercising = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_YUNA));
    	    // Create a memory device compatible with the above DC variable
    	    MemDCExercising = CreateCompatibleDC(hDC);
                 // Select the new bitmap
                 SelectObject(MemDCExercising, bmpExercising);
    
    	    // Copy the bits from the memory DC into the current dc
    	   BitBlt(hDC, 10, 10, 450, 400, MemDCExercising, 0, 0, SRCCOPY);
    
    
    	    // Restore the old bitmap
    	    DeleteDC(MemDCExercising);
    	    DeleteObject(bmpExercising);
    	    EndPaint(hWnd, &Ps);
    	    break;
    	default:
    	    return DefWindowProc(hWnd, Msg, wParam, lParam);
        }
        return 0;
    }
    [/I][/COLOR][/FONT]

  2. #2
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    New York
    Posts
    1,905
    I copied your code directly in to a temporary project and tested it out. I don't have the bmp that you're trying to use, so I drew up one really quick and compiled it. The image appeared to be drawing fine.

    One thing you might want to make sure of though, is that you included the .rc file in to your project. It will still compile fine without it, but if it's not included, the image will not show up. So if you're in visual C++, just right click on the workspace tree thing and click "Add Files to Project". Then select the .rc file that you should have in the project folder and include it. Your image should hopefully then show up (assuming you haven't already done this)

    If you're not in visual studio, you should still have a .rc file somewhere, just add it to your project and recompile.

  3. #3
    Registered User DCII764II00's Avatar
    Join Date
    Dec 2003
    Posts
    7
    [color=royalblue]
    ^^ THANKS ^^
    It worked out great, I owe you one.. I was wondering why it didn't work ^^''

    Thanks again ^^
    Farewell~
    [/font]

  4. #4
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    New York
    Posts
    1,905
    no problem, glad I could help

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, 05:35 AM
  3. Problem displaying bitmaps
    By batman123 in forum Game Programming
    Replies: 2
    Last Post: 01-09-2005, 02:01 AM
  4. Displaying Two BitMaps
    By kryptkat in forum Windows Programming
    Replies: 2
    Last Post: 12-24-2002, 08:15 PM
  5. Displaying bitmaps on a dialog
    By minesweeper in forum Windows Programming
    Replies: 2
    Last Post: 05-15-2002, 03:11 PM