Advertisement

Blitting Bitmaps with the WinAPI

Started by December 14, 1999 05:51 PM
2 comments, last by Enix 25 years ago
Does anyone have any suggestions???

------------------

Well, I guess first of all, move all the code that only needs to be done once OUT of your WM_PAINT handler like you mentioned.

Move all your clean up code to a single location as well.

Your calls to DeleteObject also need to be modified:

DeleteObject(&PicslHB) becomes DeleteObject(PicslHB)


Also, where does TilesDC come from? Does it get initialized anywhere?

Just a couple suggestions...

-mordell

__________________________________________

Yeah, sure... we are laughing WITH you ...
Advertisement
Ive been trying to make a level editor for a tile based game and ive run into a very large problem. The Tiles Window (actually its a modeless dialog, but thier basically the same thing) needs to be repainted when its resized etc. but after I blt the bitmap once it refuses to work again, unless re-loaded. of course this creats a slow program that has a HUGE memory leak in it. i currently useing the following code to blit to the dialog.
code:
PAINSTRUCT ps;HBITMAP    Pics1HB;BITMAP     Pics1BM;HDC        SrcDC;//hwndDlg is the HWND to the dialogcase WM_PAINT:    BeginPaint(hwndDlg,&ps);    Pics1HB=(HBITMAP) LoadImage(NULL, "pics1.bmp", IMAGE_BITMAP, 0, 0,LR_LOADFROMFILE | LR_CREATEDIBSECTION);    GetObject(Pics1HB,sizeof(Pics1BM),&Pics1BM);    SrcDC=CreateCompatibleDC(TilesDC);    SelectObject(SrcDC, Pics1HB);    BitBlt(TilesDC,0,0,Pics1BM.bmWidth,Pics1BM.bmHeight,SrcDC,X,Y,SRCCOPY);    DeleteObject(&Pics1HB);    DeleteObject(&Pics1BM);    DeleteObject(&SrcDC);    EndPaint(hwndDlg,&ps);break;

This code works, yet as I said above, it works very poorly. Does anyone know how to make this code better? So i only have to load the bitmap once?

Thanks for reading!
Enix

[This message has been edited by Enix (edited December 14, 1999).]

THANK YOU SO MUCH!!!!!!!!!!!!!!!!!!!!!!!

After I changed the delete object code to what you said i should it now works. I think the reason it works now is because the SelectObject() function binds SrcDC with the handle to the bitmap, and to end this binding I have to delete SrcDC. I should have had this figured out hours ago, and would have, if msdn decided they would cover a usefull topic like this, but nooo...

THANKS AGAIN!!!!!!!!!!!!!!!!!!

This topic is closed to new replies.

Advertisement