Solved

how to draw an image (begginer)

Posted on 2003-10-31
5
489 Views
Last Modified: 2012-08-13
Hi, I am a begginer in C++ and I want to draw an image in my form. I mean, I want to have a bitmap in the form's background. I am not using MFC, it's just a win32 application. What I've done so far is this:

In my project.rc file I just wrote this:

BALLBMP BITMAP "15.bmp"

In my project.cpp this is the code:

HBITMAP hbmBall;

hbmBall = LoadBitmap(hInstance, "BALLBMP");
if(!hbmBall){
   char uo[256];
itoa(GetLastError(),uo,10);MessageBox(NULL,"no se cargo el icono",uo,MB_OK);}


When I run the program, I get an error number 1814 (The specified resource name cannot be found in the image file).
What am I doing wrong?
Thank you
0
Comment
Question by:vittoriodelamancia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 16

Expert Comment

by:George Tokas
ID: 9658805
>>BALLBMP BITMAP "15.bmp"
This is not needed.
>>hbmBall = LoadBitmap(hInstance, "BALLBMP");
change to:
hbmBall = LoadBitmap(hInstance, "15.bmp");
15.bmp or yourfilename.bmp must be in the same directory or you have to specify the path.
I think that way it will work.
gtokas.
0
 

Author Comment

by:vittoriodelamancia
ID: 9659294
hi gtokas! No, it doesn't work. I had tried that before, but it doesn't work. I get the same 1814 error code.
I am using Microsoft Visual C++, and I it is a Win32 application. I don't know why it doesn't work!
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 200 total points
ID: 9660524
Don't edit .rc file directly. Open Resource view, right-click Resources and select "Add resource". Select Bitmap, import. Select 15.bmp, it will be added to resource with default resource ID like IDB_BITMAP (you can change this ID). To load such bitmap in the program write:

HBITMAP hbmBall;

hbmBall = (HBITMAP)LoadImage(hInstance, MAKEINTRESOURCE(IDB_BITMAP), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
0
 

Author Comment

by:vittoriodelamancia
ID: 9661486
Excellent!! And now to paint the form?
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 9662420
           case WM_PAINT:
                {
                    hdc = BeginPaint(hWnd, &ps);
                   
                    HBITMAP hbmBall;
                    hbmBall = (HBITMAP)LoadImage(hInst, MAKEINTRESOURCE(IDB_BITMAP), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
                   
                    BITMAP bmp;
                    GetObject(hbmBall, sizeof(BITMAP), &bmp);
                   
                    HDC hmemDC = CreateCompatibleDC(hdc);
                    SelectObject(hmemDC, hbmBall);
                   
                    BitBlt(hdc, 0, 0, bmp.bmWidth, bmp.bmHeight, hmemDC, 0, 0, SRCCOPY);
                   
                    EndPaint(hWnd, &ps);

                    DeleteDC(hmemDC);
                    DeleteObject(hbmBall);
                }
                break;
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question