Thread: Winprog BMP tutorial not working

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    26

    Winprog BMP tutorial not working

    I downloaded the winprog.org bmp tutorial and when I complile and run the program it gives the error "Could not load IDB_BALL!" which is an error handler within the program. However it should be loading the picture. I am using latest version of Dev C++. Any ideas? Here is the code:

    Code:
    #include <windows.h>
    #include "resource.h"
    
    
    const char g_szClassName[] = "myWindowClass";
    
    HBITMAP g_hbmBall;
    
    LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
    	switch(msg)
    	{
    		case WM_CREATE:
    			g_hbmBall = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BALL));
    			if(g_hbmBall == NULL)
    				MessageBox(hwnd, "Could not load IDB_BALL!", "Error", MB_OK | MB_ICONEXCLAMATION);
    		break;
    		case WM_CLOSE:
    			DestroyWindow(hwnd);
    		break;
    		case WM_PAINT:
    		{
    			// Just a note, never use a MessageBox from inside WM_PAINT
    			// The box will cause more WM_PAINT messages and you'll probably end up
    			// stuck in a loop
    
    			BITMAP bm;
    			PAINTSTRUCT ps;
    
    			HDC hdc = BeginPaint(hwnd, &ps);
    
    			HDC hdcMem = CreateCompatibleDC(hdc);
    			HBITMAP hbmOld = SelectObject(hdcMem, g_hbmBall);
    
    			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);
    		}
    		break;
    		case WM_DESTROY:
    			DeleteObject(g_hbmBall);
    			PostQuitMessage(0);
    		break;
    		default:
    			return DefWindowProc(hwnd, msg, wParam, lParam);
    	}
    	return 0;
    }
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    	LPSTR lpCmdLine, int nCmdShow)
    {
    	WNDCLASSEX wc;
    	HWND hwnd;
    	MSG Msg;
    
    	wc.cbSize		 = sizeof(WNDCLASSEX);
    	wc.style		 = 0;
    	wc.lpfnWndProc	 = WndProc;
    	wc.cbClsExtra	 = 0;
    	wc.cbWndExtra	 = 0;
    	wc.hInstance	 = hInstance;
    	wc.hIcon		 = LoadIcon(NULL, IDI_APPLICATION);
    	wc.hCursor		 = LoadCursor(NULL, IDC_ARROW);
    	wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    	wc.lpszMenuName  = NULL;
    	wc.lpszClassName = g_szClassName;
    	wc.hIconSm		 = LoadIcon(NULL, IDI_APPLICATION);
    
    	if(!RegisterClassEx(&wc))
    	{
    		MessageBox(NULL, "Window Registration Failed!", "Error!",
    			MB_ICONEXCLAMATION | MB_OK);
    		return 0;
    	}
    
    	hwnd = CreateWindowEx(
    		WS_EX_CLIENTEDGE,
    		g_szClassName,
    		"A Bitmap Program",
    		WS_OVERLAPPEDWINDOW,
    		CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,
    		NULL, NULL, hInstance, NULL);
    
    	if(hwnd == NULL)
    	{
    		MessageBox(NULL, "Window Creation Failed!", "Error!",
    			MB_ICONEXCLAMATION | MB_OK);
    		return 0;
    	}
    
    	ShowWindow(hwnd, nCmdShow);
    	UpdateWindow(hwnd);
    
    	while(GetMessage(&Msg, NULL, 0, 0) > 0)
    	{
    		TranslateMessage(&Msg);
    		DispatchMessage(&Msg);
    	}
    	return Msg.wParam;
    }
    And yes, the .bmp file, resource.h and bmp_one.rc are all present in the folder.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    Is the rc file part of your project?

  3. #3
    Registered User
    Join Date
    Mar 2005
    Posts
    26
    Quote Originally Posted by Quantum1024
    Is the rc file part of your project?
    excellent, thank you, that was the problem

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help with this tutorial program: invalid operands to binary( - )
    By convenientstore in forum C Programming
    Replies: 8
    Last Post: 06-08-2009, 12:53 PM
  2. Replies: 8
    Last Post: 05-07-2009, 11:31 AM
  3. Stencil Buffer Tutorial Port.. test me! (linux)
    By Perspective in forum Game Programming
    Replies: 3
    Last Post: 08-15-2004, 09:35 PM
  4. My DirectInput tutorial....
    By jdinger in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 06-18-2002, 11:32 PM
  5. newb looking for an SDL tutorial
    By Flikm in forum Game Programming
    Replies: 5
    Last Post: 10-12-2001, 11:11 PM