void ShowBMP(void)
{
// 4 Steps...
// 1) Get Device DC for Window (done, hDC = hMainDC)
// 2) Obtain Bitmap Handle
// 3) Create DC for Bitmap
// 4) Copy from Bitmap DC to Window DC
HANDLE hBMP;
hbmp (HBITMAP) LoadImage(hInstance,
IDB_BUBBLES,
IMAGE_BITMAP,
0, 0,
LR_CREATEDIBSECTION);
hbmp CreateCompatibleDC(NULL);
hbmp SelectObject(hMainDC, hbmp)
// What next???
Some help on displaying a Bitmap with Windows GDI
Hello Everyone. I''m working through the Game Programming Genesis Articles and having some trouble.
I''m very new to windows programming, and just learning C++ as well. Here is a code snippet of my ShowBMP() function. It is supposed to just display a Bitmap with ID ''IDB_BUBBLES'' which is loaded in as a Resource.
I just need to know what is wrong... I don''t have the last step on there yet where you copy from the Backbuffer DC to the Screen DC. Any help or code snippets showing how would help.
Some info...
I''m using MSVC++ 6.0 running Win98.
hMainDC is a handle to the main DC (duh)
hwnd is a handle to my window
I may have totally screwed this up... let me know.
~~~~~~~~~~~
Chris Vogel
~~~~~~~~~~~
WyrmSlayer RPG - In Early Development
Try this:
This should work, although if it doesn''t, remember, i am not very good with the GDI so this may not even be the best way to do it.
------------------------------
BASIC programmers don''t die, they just GOSUB and don''t return.
void ShowBMP(void){ HBITMAP hBMP; HBITMAP hbmOld; BITMAP bm; HDC hMemDC; hBMP = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_BUBBLES)); hMemDC = CreateCompatibleDC(hMainDC); hbmOld = SelectObject(hMemDC, hBMP); GetObject(hBMP, sizeof(bm), &bm); BitBlt(hMainDC, 0, 0, bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY); SelectObject(hMemDC, hbmOld); DeleteDC(hMemDC); DeleteObject(hBMP);}
This should work, although if it doesn''t, remember, i am not very good with the GDI so this may not even be the best way to do it.
------------------------------
BASIC programmers don''t die, they just GOSUB and don''t return.
------------------------------BASIC programmers don't die, they just GOSUB and don't return.
quote: Original post by Radagar
I may have totally screwed this up... let me know.
Um, yeah, but don''t fret about it.
void ShowBMP(void){ // 4 Steps... // 1) Get Device DC for Window (done, hDC = hMainDC) // 2) Obtain Bitmap Handle // 3) Create DC for Bitmap // 4) Copy from Bitmap DC to Window DC HANDLE hBMP;// you have to assign the value returned by the function to // the appropriate type of variable // assign means "set equal to" so set the equation hBMP = (HBITMAP) LoadImage(hInstance, IDB_BUBBLES, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);// also note that variable names are case sensitive// hbmp is not the same as hBMP// here you need to declare the appropriate kinds of variables to // receive the return values from the functions HDC hDC = CreateCompatibleDC(NULL); HBITMAP hOldBmp = SelectObject(hMainDC, hBMP);//.... hOldBmp = SelectObject(hMainDC, hOldBmp); ReleaseDC(hwnd, hDC);
Um - you know, you probably ought to start with something easier, get a feel for how to program and then come back to those articles. Get yourself an intro to C or C++ book and go through that first, then maybe get a copy of Charles Petzold''s "Programming Windows" - then come back to gaming.
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
Thanks for the replies!
~~~~~~~~~~~
Chris Vogel
~~~~~~~~~~~
~~~~~~~~~~~
Chris Vogel
~~~~~~~~~~~
WyrmSlayer RPG - In Early Development
quote: BASIC programmers don''t die, they just GOSUB and don''t return.
LOL, Love that.
~~~~~~~~~~~
Chris Vogel
~~~~~~~~~~~
WyrmSlayer RPG - In Early Development
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement