Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Blitting Bitmaps with the WinAPI


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
3 replies to this topic

#1 Enix   Members   -  Reputation: 122

Like
Likes
Like

Posted 14 December 1999 - 11:51 AM

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 dialog


case 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).]


Sponsor:

#2 Enix   Members   -  Reputation: 122

Like
Likes
Like

Posted 14 December 1999 - 10:48 AM

Does anyone have any suggestions???

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


#3 mordell   Members   -  Reputation: 122

Like
Likes
Like

Posted 14 December 1999 - 11:39 AM

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


#4 Enix   Members   -  Reputation: 122

Like
Likes
Like

Posted 14 December 1999 - 11:51 AM

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!!!!!!!!!!!!!!!!!!





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