Archived

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

CoolMike

Loading a Bitmap into a DC

Recommended Posts

CoolMike    122
Even though I already know a lot of DirectX, I still can''t quite get DirectDraw to run in a window. So I''ve decided to broaden my skills and learn MFC. My goal is just to make a simple windowed game anyways, so using DirectX isn''t really important. So here is my question - How do I load *.bmp files into a device context so I can draw sprites on my window?

Share this post


Link to post
Share on other sites
Mike    141
You can visit my web page and download the BitBlt demo I have there. I created this to help a friend learn to use BitBlt. I don''t remember exactly what the program does, but the zip file contains a bitmap and the program uses BitBlt so I''m guessing that it will answere your question.

Share this post


Link to post
Share on other sites
The_C_Guy    122
Here is a simple way of loading a bitmap from a ".rc" file.

HDC DC, MemDC;
HWND hwnd;
HBITMAP hBitmap;
HINSTANCE hInst;

hBitmap = LoadBitmap(hInst, "MY_BITMAP");

DC = GetDC(hwnd);
MemDC = CreateCompatibleDC(DC);
SelectObject(MemDC, hTileBitmap);
BitBlt(DC, 0, 0, 128, 128, MemDC, 0, 0, SRCCOPY);
DeleteDC(MemDC);
ReleaseDC(hwnd, DC);

//Put this in the reasource file

MY_BITMAP BITMAP "something.bmp"



Edited by - The_C_Guy on July 19, 2000 5:13:14 PM

Share this post


Link to post
Share on other sites
Gladiator    127
Use LoadImage() if you don''t want to read the bitmap data on your own!

----------------------------------------------
That's just my 200 bucks' worth!

..-=gLaDiAtOr=-..

Share this post


Link to post
Share on other sites
CoolMike    122
Wow, thanks guys. It took me about five minutes to get a bitmap loaded after reading your posts. Now if only I could figure these kinds of things out myself. Now on to bigger and better things, like making buttons. Anybody know anything about those?

Share this post


Link to post
Share on other sites
NuffSaid    122
I take it you mean the standard window buttons. Call CraeteWindow and specify "BUTTON" in the class name.
    

hButton = CreateWindow("BUTTON",
"Click Me",
WS_CHILD|BS_PUSHBUTTON|BS_TEXT,
20,20,100,40
hWnd,//parent window

NULL,
hInst,
NULL);


That should do the trick




========================================================
If something sounds stupid but works, it's not stupid

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
try adding WS_VISIBLE in the flags.

Hope that helps

Share this post


Link to post
Share on other sites
Tom    352
While we''re on the topic of blitting and device contexts, can somebody tell me how to load a bitmap onto a DirectDraw surface without using the CreateSurfaceFromFile function? This is because I''d like to use an image library (like OpenIL) to load compressed images. I use Visual Basic.

Thanks for your help.

Share this post


Link to post
Share on other sites