🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Please Help a Beginner

Started by
1 comment, last by GameDev.net 24 years, 10 months ago
Alright, first of all, assume for this example the bitmap your trying to load is "image.bmp".

First load it.
if it's in a resource:
HBITMAP hbmp;
hbmp = LoadBitmap(hInst, "image.bmp");
//hInst is just your HINSTANCE, use
//the first paramater to your WinMain
//function

if it's just a file NOTE only win95+)
HBITMAP hbmp;
hbmp = (HBITMAP)LoadImage(hInst, "image.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);

next to load it into an HDC.

hdc BitmapHDC, hdc;
hdc = GetDC(hwnd);
BitmapHDC = CreateCompatibleDC(hdc);
SelectObject(BitmapHDC, hbmp);

// hwnd is the HWND you used for your
// CreateWindow call. It helps
// to make this variable global.

Finally, when you want to display your bitmap, here's how you do it:

BitBlt(hdc,
int nXDest,
int nYDest,
int nWidth,
int nHeight,
BitmapHDC,
int nXSrc,
int nYSrc,
SRCCOPY
);
// ok, hdc is the same one from above.
// xDest is the x coord of where you blit to
// yDest is the y coord of where you blit to
// nWidth is the width of your image
// nHeight is the height of your image
// XSrc is the x coord of where you get from your image, usually 0.
// YSrc is the y coord of where you get from your image, usually 0.


and that's it. When your closing your app, do the following to clean up any memory you allocated:

ReleaseDC(hwnd, BitmapHDC);
ReleaseDC(hwnd, hdc);
DeleteDC(BitmapHDC);
DeleteDC(hdc);

Advertisement

Hello, I am learning to program using the WINAPI, not MFC, but I thought that someone here may be able to help me anyway. I am able to create a simple window, and draw shaped in it using GDI. But drawing shaped limits the things I can do, so I would like to know how to display a bitmap in my window. Please, I am rather young, so I dont have much money to purchase a book about windows programming, and I have searched the web, but I cant find anything that is very useful. If you know of any places that I can get a tutorial on how to display a bitmap in my window, please tell me. (I looked at the tutorial at reliablesoftware, so dont give me a link to that one please)
I use the Borland C++ 4.52 Compiler to compile and write my programs. Any help would be appreciated greatly. Thank you.
-Brad


Maybe you should get the DirectX SDK and start learning DirectDraw. DDraw is easy to learn and you can do things really fast using hardware-acceleration. And you normally don't need a book, the documentation in the SDK is ok.

Bye

------------------
Skullpture Entertainment
#40842461

Graphix Coding @Skullpture Entertainmenthttp://www.skullpture.de

This topic is closed to new replies.

Advertisement