• Advertisement

Archived

This topic is now archived and is closed to further replies.

Guest Anonymous Poster

Please Help a Beginner

This topic is 6750 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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);

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster

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


Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

  • Advertisement