Advertisement

help in putting a bitmap

Started by November 20, 2001 05:55 AM
17 comments, last by mickey 23 years ago
hi! please help i''m stuck for a week now figuring out how to load and show a bitmap to the screen. please mention step by step including the functions that i''ll be using. thanks!
http://www.dualforcesolutions.comProfessional website designs and development, customized business systems, etc.,
please mention libray/API u r using.. (eg: DirectX, OpenGL, etc..)

(always anonymous)
Advertisement
oh okey, i''m using ms vc 6 and directx
http://www.dualforcesolutions.comProfessional website designs and development, customized business systems, etc.,
okey this is what i did,

// somewhere in the winmain(HISNTANCE hInstance......):
HBITMAP bmp;
bmp = LoadBitmap(hInstance, "xxxxxx.bmp");
//in window procedure:
HDC hdc;
//in the WM_PAINT:
GetDC(&hdc);
SelectObject(hdc, bmp);
GetObject(bmp, sizeof(BITMAP), &bmp);
BitBlt(hdc, 100, 100, 300, 300, hdc, 0, 0, SRCCOPY);

there! can''t get to show it on my screen
http://www.dualforcesolutions.comProfessional website designs and development, customized business systems, etc.,
You aren''t using directx here. You''re attempting to use GDI, which is windows'' internal graphics interface. Its very slow compared to directx. What you want to do is set up directx, and texture a quad with your bitmap. If you look in the directx sdk docs, there are tutorials with code on exactly how to do this.
Good luck.

"You are too useless. And now I must beat you." - English subtitle in a Honk Kong Movie.
lunarss is right, there''s no DX in your code. However, if you want to try GDI before tackling DX (which might be a good idea), read about BitBlt in the manual. The problem is that you''re trying to BitBlt a DC to itself (using the same argument for hdcDest and hdcSrc). You need to create an off-screen DC, select the bitmap into that, and blit it to your window''s DC.

Try something like this for the WM_PAINT handler:

HDC hTempDC = CreateCompatibleDC(NULL); // Create an off-screen DC
HBITMAP hOldBmp = (HBITMAP)SelectObject(hTempDC, bmp); // Select the bitmap
BitBlt(hDC, 100, 100, 300, 300, hTempDC, 0, 0, SRCCOPY); //Blit
SelectObject(hTempDC, hOldBmp); // Restore the off-screen DC
DeleteDC(hTempDC); // Delete the off-screen DC
Advertisement
Hi! actually i was using DX i just omitted the stuffs like

if (lpDDSPrimary->GetDC(&hdc) == DD_OK) { etc.,

to simplify things, actually i know basically how it is done, i just can''t figure it out how to blit my "own" bitmaps. maybe it has something to do with the resource tab?? coz what i do is,
right-click on resource folder on the workspace manager, click on add files to folder and chose one of my bitmap say for example xxxx.bmp, then on my code whereas the line:

hBitmap = LoadBitmap (hInstance, "xxxx.bmp");

i put on the 2nd parameter the filename of my bitmap, is that wrong? actually i already tried copy and paste from someone else code already like for example:

hBitmap = LoadBitmap (hInstance, TEXT ("Bricks")) ;

and i just replaced that 2nd parameter with my bitmap''s filename and there it is, doesn''t work!

p.s. my bmp file also resides on the same directory.
Sorry, I don''t get it. Do you load the bitmap from disk or from a resource?

Check the manual on handling errors from LoadBitmap(). The error code will probably tell you something about what''s wrong.
i think that''s my problem Ulf O, what i did is, i inserted a bmp file in my workspace and i used that bmp filename on the second parameter of the LoadBitmap() function i mean just try mention anything it might help me solve my problem, thanks
http://www.dualforcesolutions.comProfessional website designs and development, customized business systems, etc.,
plz help! i really can''t figure it out! okey i want to load my bitmap from a resource file. this is what''s inside my .rc file:

// resource.rc
IDB_BITMAP1 BITMAP DISCARDABLE "bitmap1.bmp"

// then in my WM_CREATE, i did this
HBITMAP hbitmap = LoadBitmap(hInstance, IDB_BITMAP1);
// which returns error indicating cannot convert char to int something like that,

// so i changed it to
HBITMAP hbitmap = LoadBitmap(hInstance, "bitmap1.bmp");
GetObject (hBitmap, sizeof (BITMAP), &bitmap) ; // do i have to use this?
// then it works no error, but still it doesn''t blit my bitmap! Please tell me what''s wrong with it, already been through with a lot of books and all of them offers almost the same style on blitting a bitmap why can''t i make mine work! thanks!

This topic is closed to new replies.

Advertisement