PDA

Click to See Complete Forum and Search --> : Generated DC problems!!!


nameJack
Dec 19th, 2000, 10:30 PM
Each time when I click on a command button, the procedure commandbutton_click is executed...

Inside the commandbutton_click procedures, a mask image and sprite image will be generated using the GenerateDC and BitBlt function and it'll move 10 pixels left.

therefore, whenever the commandbutton is click, a sprite will be generated and it'll move around the screen 10 pixels left

now the problem is, after hundreds time clicking the button, the 'low memory' or 'low resources' message is displayed.

Although, i've added deleteDC function in every click, the problem never subside.
To make the matter worse, after exiting the program, the windows will be messed up... signs of not enough memory...

Can anyone help me?


Private Sub CommandButton_Click()
Dim Move
Move = 10
Move = Move + 10

'load images
DCMask = GenerateDC("c:\1m.bmp")

If DCMask <= 0 Then
MsgBox "Failure in creating mask dc"
Exit Sub
End If

DCSprite = GenerateDC("c:\1.bmp")

If DCSprite <= 0 Then
MsgBox "Failure in creating sprite dc"
'Clean up after the created mask
DeleteGeneratedDC DCMask
End If

'add the sprite and the mask

BitBlt Me.hdc, 0, Move, 30, 30, DCMask, 0, 0, vbSrcAnd
BitBlt Me.hdc, 0, Move, 30, 30, DCSprite, 0, 0, vbSrcPaint

'delete the images after generated
DeleteGeneratedDC DCMask
DeleteGeneratedDC DCSprite

frmTest.Cls
frmtest.Refresh



This is not the real code, but just to give you the main idea
Any suggestion?

kedaman
Dec 20th, 2000, 03:03 AM
You should use ReleaseDC instead of DeleteDC

nameJack
Dec 20th, 2000, 03:41 AM
Can you please give me the code for releaseDC if it's not too much trouble...

Btw, what's the difference between DeleteDC and ReleaseDC

and how do you apply releaseDC on generatedDC
Thanx

[Edited by nameJack on 12-20-2000 at 04:45 AM]

kedaman
Dec 20th, 2000, 04:34 AM
I have no idea from where you got generateDC, i guess it's a procedure you have from before that loads a bitmap and then attaches it to a DC without you have to worry about that. In that case i think you have to release the bitmap too. Deleteobject should do the trick. Before i get further i need to know how this generateDC looks like, it would be easier to work with it if you store the bitmap handle.
I'm not sure what the difference is between deleteDC and releaseDC, except that DeleteDC doensn't do what i also once thought was freing up the handle.

nameJack
Dec 20th, 2000, 09:25 AM
Well... i guess i had to upload this project...
http://www.geocities.com/weirdteenage/project.zip
Try and see if theres something wrong
the message box was put up to indicate the error
when you move the sprite 200 times or more
the messagebox icon will turn black indicating low memory

Actually i would prefer if u could give me another way of doing so?

take a look at the project...:)

[Edited by nameJack on 12-20-2000 at 10:30 AM]