Jump to content

  • Log In with Google      Sign In   
  • Create Account


Please Help a Beginner


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 01 August 1999 - 02:01 PM

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




Sponsor:

#2 Funkymunky   Members   -  Reputation: 590

Like
Likes
Like

Posted 28 July 1999 - 06:46 PM

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



#3 NuFAN   Members   -  Reputation: 122

Like
Likes
Like

Posted 01 August 1999 - 02:01 PM

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





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS