|
-
Oct 5th, 2001, 04:38 AM
#1
Thread Starter
Retired VBF Adm1nistrator
Does DeleteDC() even work ?
Correct me if I'm wrong, but surely the code below should be able to run indefinitely, as it is deleting the DC right after it creates it ??
If not, then how does one actually recover the lost resources ?
VB Code:
Option Explicit
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hDc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hDc As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hDc As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hDc As Long, ByVal hObject As Long) As Long
Private Declare Sub GlobalMemoryStatus Lib "kernel32" (lpBuffer As MEMORYSTATUS)
Private Type MEMORYSTATUS
dwLength As Long
dwMemoryLoad As Long
dwTotalPhys As Long
dwAvailPhys As Long
dwTotalPageFile As Long
dwAvailPageFile As Long
dwTotalVirtual As Long
dwAvailVirtual As Long
End Type
Private Function GenerateDC(FileName As String) As Long
Dim DC As Long, picTemp As IPictureDisp
DC = CreateCompatibleDC(0)
If DC < 1 Then
Exit Function
End If
Set picTemp = LoadPicture(FileName)
SelectObject DC, picTemp
DeleteObject picTemp
Set picTemp = Nothing
GenerateDC = DC
End Function
Private Sub Form_Load()
Dim i As Long
Do
DoEvents
Debug.Print "Memory Free : " & (x.dwAvailPhys / 1024) & "Kb : " & IIf(DeleteDC(GenerateDC("c:\boilogo.gif")) <> 0, "DeleteDC() Worked", "DeleteDC() Failed")
DoEvents
Loop
End Sub
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Oct 5th, 2001, 05:04 AM
#2
PowerPoster
Yes it works fine. I also had long time problems with
that crappy thing but finally I found a solution to load
bitmaps and create memory DCs and after all releas
all resources. So heres what to do:
Code:
Dim DC As Long
Dim Temp As IPictureDisp
Dim Original As Long
'Load the bitmap
DC = CreateCompatibleDC(MainWindow.hDC)
Set Temp = LoadPicture(FileName)
Original = SelectObject(DC, Temp)
'---
'Here you can use your bitmap
'BitBlt etc.
'The whole game you can say :)
'---
'Release again
SelectObject DC, Original
DeleteObject Temp
DeleteDC DC
Now this should work fine
-
Oct 5th, 2001, 11:19 AM
#3
Thread Starter
Retired VBF Adm1nistrator
Fox, if I was a puff I'd kiss you.
Thanks for that.
I'll try it at home later this evening.
Cheers,
Jamie.
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Oct 5th, 2001, 01:36 PM
#4
Addicted Member
Re: Does DeleteDC() even work ?
Originally posted by plenderj
Correct me if I'm wrong, but, Don't DCs can be negative too? I think you should change that "< 1" to "= 0".
-
Oct 5th, 2001, 02:30 PM
#5
PowerPoster
-
Oct 5th, 2001, 05:27 PM
#6
Addicted Member
Yes, if you read the API docs you have to release all objects allocated to the DC.
"1 4m 4 1337 #4xz0r!'
Janus
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
|