Results 1 to 3 of 3

Thread: BitBlt and Memory

  1. #1

    Thread Starter
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    I have this problem that I am sure is cause by this

    Code:
    Dim SButtons As Long
    Dim SkinTop As Long
    Dim SBody As Long
    Dim hBitmap As BITMAP
    Dim ButtonsBitmap As BITMAP
    
    SButtons = CreateCompatibleDC(0)
    SkinTop = CreateCompatibleDC(0)
    SBody = CreateCompatibleDC(0)
    
    imgTemp = LoadImage(ByVal 0&, bmpName, 0, 0, 0, LR_LOADFROMFILE Or LR_CREATEDDIBSECTION)
    SelectObject SBody, imgTemp
    GetObjectAPI imgTemp, Len(hBitmap), hBitmap
    DeleteObject imgTemp
    BitBlt frmTechAmp.picBody.hdc, 0, 0, me.picBody.ScaleWidth, me.picBody.ScaleHeight, SBody, 0, 0, vbSrcCopy
    
    DeleteDC SButtons
    DeleteDC SkinTop
    DeleteDC SBody
    It doesn't happen right away but after a bunch of compiles VB will give me an out of memory error. Any ideas why? Or is there away to be sure that while unloading that everything that is taking up memory gets released?

  2. #2
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    Code:
    Dim SButtons As Long
    Dim SkinTop As Long
    Dim SBody As Long
    Dim hBitmap As BITMAP
    Dim ButtonsBitmap As BITMAP
    
    SButtons = CreateCompatibleDC(0)
    SkinTop = CreateCompatibleDC(0)
    SBody = CreateCompatibleDC(0)
    
    imgTemp = LoadImage(ByVal 0&, bmpName, 0, 0, 0, LR_LOADFROMFILE Or LR_CREATEDDIBSECTION)
    SelectObject SBody, imgTemp
    GetObjectAPI imgTemp, Len(hBitmap), hBitmap
    DeleteObject imgTemp
    BitBlt frmTechAmp.picBody.hdc, 0, 0, me.picBody.ScaleWidth, me.picBody.ScaleHeight, SBody, 0, 0, vbSrcCopy
    
    DeleteDC SButtons
    DeleteDC SkinTop
    DeleteDC SBody

    when you use select object it replaces the object attatched to the DC with the new object and returns the old object's handle

    change this to

    Code:
    Dim SButtons As Long
    Dim SkinTop As Long
    Dim SBody As Long
    Dim hBitmap As BITMAP
    Dim ButtonsBitmap As BITMAP
    
    SButtons = CreateCompatibleDC(0)
    SkinTop = CreateCompatibleDC(0)
    SBody = CreateCompatibleDC(0)
    
    imgTemp = LoadImage(ByVal 0&, bmpName, 0, 0, 0, LR_LOADFROMFILE Or LR_CREATEDDIBSECTION)
    DeleteObject SelectObject(SBody, imgTemp)
    GetObjectAPI imgTemp, Len(hBitmap), hBitmap
    DeleteObject imgTemp
    BitBlt frmTechAmp.picBody.hdc, 0, 0, me.picBody.ScaleWidth, me.picBody.ScaleHeight, SBody, 0, 0, vbSrcCopy
    
    DeleteDC SButtons
    DeleteDC SkinTop
    DeleteDC SBody

    and that should solve your problem

  3. #3

    Thread Starter
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    That seems to have worked thanks

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