Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 618669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:34:18+00:00 2026-05-13T18:34:18+00:00

I am following a tutorial. And I am trying to draw a .bmp file

  • 0

I am following a tutorial. And I am trying to draw a .bmp file to the screen. It builds with no errors but no image appears. according to the book, I should see the image pop up in random places. Below is my code. The author doesnt recommend this technique for drawing objects, he is just doing for demostration. In case your wondering.

The image is a 25×25 square red square.

#include <windows.h>
#include <iostream>
#include <time.h>

using namespace std;

const string APPTITLE = "Game Loop";
HWND window;
HDC device;
bool gameover = false;


void DrawBitmap(char *filename, int x, int y)
{
 //load the bitmap image
 HBITMAP image = (HBITMAP)LoadImage(0,"c.bmp", IMAGE_BITMAP,0,0, LR_LOADFROMFILE);

 BITMAP bm;
 GetObject(image, sizeof(BITMAP), &bm);

 HDC hdcImage = CreateCompatibleDC(device);
 SelectObject(hdcImage,image);

 BitBlt(
  device,
  x,y,
  bm.bmWidth, bm.bmHeight,
  hdcImage,
  0,0,
  SRCCOPY);

 //deletec the device context and bitmap
 DeleteDC(hdcImage);
 DeleteObject((HBITMAP)image);
}

bool Game_Init()
{
 srand(time(NULL));
 return 1;
}

void Game_Run()
{
 if(gameover == true) return;

 RECT rect;
 GetClientRect(window, &rect);

 //draw bitmap at random location
 int x = rand() % (rect.right - rect.left);
 int y = rand() % (rect.bottom - rect.top);

 DrawBitmap("c.bmp",x,y);
}

void Game_End()
{
 //free the device
 ReleaseDC(window,device);
}

LRESULT CALLBACK WinProc(HWND hWnd, UINT message, WPARAM WParam, LPARAM lparam)
{
 switch(message)
 {
  case WM_DESTROY:
   gameover = true;
   PostQuitMessage(0);
  break;
 }

 return DefWindowProc(hWnd, message, WParam, lparam);
}

ATOM MyRegisterClass(HINSTANCE hInstance)
{
 //set the new windows properties

 WNDCLASSEX wc;

 wc.cbSize  = sizeof(WNDCLASSEX);
 wc.style  = CS_HREDRAW | CS_VREDRAW;
 wc.lpfnWndProc = (WNDPROC) WinProc;
 wc.cbClsExtra = 0;
 wc.cbWndExtra = 0;
 wc.hInstance = hInstance;
 wc.hIcon  = NULL;
 wc.hCursor  = LoadCursor(NULL, IDC_ARROW);
 wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
 wc.lpszMenuName = NULL;
 wc.lpszClassName= APPTITLE.c_str();
 wc.hIconSm  = NULL;

 return RegisterClassEx(&wc);
}

bool InitInstance(HINSTANCE hInstance, int nCmdShow)
{
 //create a  new window
 window = CreateWindow(
  APPTITLE.c_str(),
  APPTITLE.c_str(),
  WS_OVERLAPPEDWINDOW,
  CW_USEDEFAULT, CW_USEDEFAULT,
  640,480,
  NULL,
  NULL,
  hInstance,
  NULL);

 //was there an error creating the window ?
 if(window == 0) return 0;

 //display the window 
 ShowWindow(window, nCmdShow);
 UpdateWindow(window);
 device = GetDC(window);

 return 1;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
      LPSTR lpCmdLine, int nCmdShow)
{
 //declare variables
 MSG msg;

 //register the class
 MyRegisterClass(hInstance);

 //initialize application
 if(!InitInstance(hInstance, nCmdShow)) return 0;

 //initilize the game
 if(!Game_Init()) return 0;

 //main message loop
 while(!gameover)
 {
  if(PeekMessage(&msg,NULL, 0, 0,PM_REMOVE))
  {
   TranslateMessage(&msg);
   DispatchMessage(&msg);
  }
  Game_Run();
 }

 Game_End();

 return msg.wParam;
}

I am not sure if its because I have the image in the wrong location. but if that was the case. I figure it would throw a error. I have the image placed at the root of my source folder.

[EDIT]

Also , when I rebuild, I get a warning which might be a cause but here is the warning

1>------ Rebuild All started: Project: Begin, Configuration: Debug Win32 ------
1>Deleting intermediate and output files for project 'Begin', configuration 'Debug|Win32'
1>Compiling...
1>main.cpp
1>c:\users\numerical25\documents\visual studio 2008\projects\begin\begin\main.cpp(39) : warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
1>Compiling manifest to resources...
1>Microsoft (R) Windows (R) Resource Compiler Version 6.1.6723.1
1>Copyright (C) Microsoft Corporation.  All rights reserved.
1>Linking...
1>LINK : C:\Users\numerical25\Documents\Visual Studio 2008\Projects\Begin\Debug\Begin.exe not found or not built by the last incremental link; performing full link
1>Embedding manifest...
1>Microsoft (R) Windows (R) Resource Compiler Version 6.1.6723.1
1>Copyright (C) Microsoft Corporation.  All rights reserved.
1>Build log was saved at "file://c:\Users\numerical25\Documents\Visual Studio 2008\Projects\Begin\Begin\Debug\BuildLog.htm"
1>Begin - 0 error(s), 1 warning(s)
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

alt text

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T18:34:19+00:00Added an answer on May 13, 2026 at 6:34 pm

    The code does work, you just forgot to put your c.bmp in the right location. Put it in the project output folder (i.e. bin/Debug) if you’re launching the program from Explorer or to the project folder if you’re lanching the program from Visual Studio.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

friends, i am trying to upload file to php server using following tutorial http://getablogger.blogspot.com/2008/01/android-how-to-post-file-to-php-server.html
I am trying to go through the following tutorial on asp.net. When I get
Android twitter Trying the following tutorial for Oauth based authentication and updating user status.
Trying the following tutorial http://www.androidsdkforum.com/android-sdk-development/3-oauth-twitter.html i am having trouble understanding callback URL my twitter
I'm following several tutorials and references trying to get my kernel set up. I've
I've been following this tutorial (lesson 6) in order to build and deploy a
I'm following this tutorial (seems good) for Rails. After I run ruby script/generate scaffold
I've just started playing with Django and am loosely following the tutorial with my
I've been experimenting with ASP.NET MVC and following this tutorial to create the basic
I am following a VB tutorial to do some HTML manipulation using LINQ It

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.