|
-
Jul 10th, 2001, 05:06 AM
#1
Thread Starter
PowerPoster
YoungBuck
Code:
dim a as long
dim dc as long
dim temp as ipicturedisp
dim orig as Long
for a=0 to 100
'Load
dc = createcompatibledc(me.hdc)
set temp=loadpicture("c:\test.bmp")
' get handle to original bitmap created with DC
orig = selectobject(dc, temp)
'Release
' put the original bitmap back into the DC
selectobject dc, orig
' delete the bitmap that was created
deleteobject temp
' free the DC's resources
deletedc dc
next
Do I really need to keep the Temp picture alive until I shutdown the game??
-
Jul 10th, 2001, 07:14 AM
#2
Addicted Member
Nope.
I think you can delete the bitmap out of the DC at anytime.
So all you need to do is Delete the bitmap before putting another one into the DC
Some Days, i just get this feeling that i'm helping to write dozens of Viruses...
-
Jul 10th, 2001, 11:29 AM
#3
transcendental analytic
Sounds weird, it's your choise fox, what do you need the bitmap for?
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Jul 10th, 2001, 12:55 PM
#4
Thread Starter
PowerPoster
I just neet the bitmap to get the DC... therefore everything in my original code worked fine, excepting the memory leak..
Ok let me ask the question the other way around:
What is the correct code to load a bitmap into memory, get it's DC, release everything excepting the DC (which I use in the program) and when done release the DC, too.?
-
Jul 10th, 2001, 01:38 PM
#5
Addicted Member
Code:
dim a as long
dim dc as long
dim temp as ipicturedisp
dim orig as Long
dc = createcompatibledc(me.hdc)
for a=0 to 100
'Load
set temp=loadpicture("c:\test.bmp")
' get handle to original bitmap created with DC
orig = selectobject(dc, temp)
'Release
' put the original bitmap back into the DC
selectobject dc, orig
' delete the bitmap that was created
deleteobject temp
next
' free the DC's resources
deletedc dc
there
Some Days, i just get this feeling that i'm helping to write dozens of Viruses...
-
Jul 10th, 2001, 01:43 PM
#6
Thread Starter
PowerPoster
Thanks 
Maybe you'll all get into the credits when I'm done
-
Jul 10th, 2001, 03:43 PM
#7
transcendental analytic
Originally posted by Fox
I just neet the bitmap to get the DC... therefore everything in my original code worked fine, excepting the memory leak..
Ok let me ask the question the other way around:
What is the correct code to load a bitmap into memory, get it's DC, release everything excepting the DC (which I use in the program) and when done release the DC, too.?
Ok you must have missunderstood something here.
DC are not something you get from bitmaps, or more specifically Device Independent Bitmaps (DIB), they are interfaces for screen or ofscreen graphical areas which GDI uses as handles for performing graphical operations on (like drawing and blitting), the offscreen device you need to handle blits from a DIB is created from the GDI with CreatecompatibleDC not retrieved from the bitmap.
Now I suppose you need the bitmap for something right, you need to blit from it say, you attach it to the offscreen DC using selectobject. Then you won't need it anymore, you detach it by calling selectobject again without passing a handle and the DC should be null, if you want to attach another bitmap, pass it's handle with selectobject instead. Selectobject will return the old handle which you have to deleteobject, that is if you don't need it anymore. DeleteDC is used to delete the DC when everything is done.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Jul 10th, 2001, 09:13 PM
#8
Fanatic Member
You need to keep the orig variable and Select it back into the DC before calling DeleteDC, in other words the same objects that were created along with the DC need to be Selected back into it before you call DeleteDC (Bitmaps, Pens, Brushes).
{Insert random techno-babble here}
{Insert quote from some long gone mofo here}
-
Jul 11th, 2001, 01:43 AM
#9
Thread Starter
PowerPoster
Ok, think I got it ... more or less.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|