Thread: bitmap problem

  1. #1
    yes, I'm registered!!! algi's Avatar
    Join Date
    Nov 2004
    Location
    Ipswich
    Posts
    161

    bitmap problem

    Can anybody compile the below and help me fix the error. I've being trying to get bitmaps to work for ages. If you can't does anybody know of a Bitmap tutorial for Dev C++ users. Thanks

    Code:
    #include <windows.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, "E:/Alex's Stuiff/Programming/win32/exercising.bmp"));
    	    // 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 started out with nothing and I still have most of it left.

  2. #2
    Registered User Dante Shamest's Avatar
    Join Date
    Apr 2003
    Posts
    970
    Code:
    	    // Load the bitmap from the resource
    	    bmpExercising = LoadBitmap(hInst, "E:/Alex's Stuiff/Programming/win32/exercising.bmp"));
    Although the comment says you're loading the bitmap from a resource, what you're actually doing is loading the bitmap from a file.

    If you wish to load the bitmap from a file, use LoadImage.

    Code:
    hBitmap = (HBITMAP)LoadImage(NULL,filename,IMAGE_BITMAP,0,0,LR_LOADFROMFILE) ;

  3. #3
    yes, I'm registered!!! algi's Avatar
    Join Date
    Nov 2004
    Location
    Ipswich
    Posts
    161
    when i type in the path to the image it contins "e:\alex's stuff..." and the compiler says \a is unknown. How do i get around this
    I started out with nothing and I still have most of it left.

  4. #4
    Rabite SirCrono6's Avatar
    Join Date
    Nov 2003
    Location
    California, US
    Posts
    269
    > "e:\alex's stuff..."
    Since \ begins an escape character you need to either use \\ or / in strings.

    - SirCrono6
    From C to shining C++!

    Great graphics, sounds, algorithms, AI, pathfinding, visual effects, cutscenes, etc., etc. do NOT make a good game.
    - Bubba

    IDE and Compiler - Code::Blocks with MinGW
    Operating System - Windows XP Professional x64 Edition

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Bitmap saving problem
    By geek@02 in forum Windows Programming
    Replies: 3
    Last Post: 10-01-2007, 08:44 PM
  2. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  3. Bitmap Displaying Problem
    By MadCow257 in forum Game Programming
    Replies: 0
    Last Post: 01-25-2005, 05:21 PM
  4. Reading Bitmap File Header Problem.
    By StanleyC in forum C Programming
    Replies: 7
    Last Post: 08-26-2004, 05:54 PM
  5. Problem With My Bitmap
    By Sebastiani in forum Windows Programming
    Replies: 9
    Last Post: 10-29-2001, 09:54 PM