vittoriodelamancia
asked on
how to draw an image (begginer)
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) ;MessageBo x(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
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)
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
ASKER
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!
I am using Microsoft Visual C++, and I it is a Win32 application. I don't know why it doesn't work!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Excellent!! And now to paint the form?
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;
{
hdc = BeginPaint(hWnd, &ps);
HBITMAP hbmBall;
hbmBall = (HBITMAP)LoadImage(hInst, MAKEINTRESOURCE(IDB_BITMAP
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;
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.