Results 1 to 9 of 9

Thread: YoungBuck

  1. #1

    Thread Starter
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088

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

  2. #2
    Addicted Member
    Join Date
    Apr 2000
    Location
    England
    Posts
    246
    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...

  3. #3
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  4. #4

    Thread Starter
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    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.?

  5. #5
    Addicted Member
    Join Date
    Apr 2000
    Location
    England
    Posts
    246
    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...

  6. #6

    Thread Starter
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Thanks

    Maybe you'll all get into the credits when I'm done

  7. #7
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  8. #8
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    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}

  9. #9

    Thread Starter
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    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
  •  



Click Here to Expand Forum to Full Width