can somebody please tell me where the appropriate place to insert "ReleaseDC" is, and how to use it? I've read that the lack of releasedc may be the primary cause of my horrible memory leak.

VB Code:
  1. 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
  2. Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
  3. Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
  4. Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
  5. Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
  6. Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
  7. Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
  8. Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
  9. Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
  10.  
  11. 'our Buffer's DC
  12. Public myBackBuffer As Long
  13. Public myBufferBMP As Long
  14.  
  15. 'The DC of our sprite/graphic
  16. Public mySprite As Long
  17. Dim AvoidLobby As Integer
  18. Dim stoptimer As Integer
  19. Dim idleornot As Long
  20. Dim xscan As Integer
  21. Dim yscan As Integer
  22. Dim Card(1 To 7) As Integer
  23. Dim cardsuit(1 To 8)
  24. Dim whichcard As Integer
  25. Dim colorcount As Integer
  26. Dim colorcounttwo As Integer
  27. Dim colorcountone As Integer
  28. Dim colorcountfour As Integer
  29. Dim colorcountfive As Integer
  30. Dim seat(1 To 10) As Integer
  31. Dim playercount As Integer
  32. Dim scanloop As Integer
  33. Dim player(1 To 11) As Integer
  34. Dim dealerbutton(1 To 10) As Integer
  35. Dim fiftycentchips(1 To 11) As Integer
  36. Dim onedollarchips(1 To 11) As Integer
  37. Dim fivedollarchips(1 To 11) As Integer
  38. Dim twentyfivedollarchips(1 To 11) As Integer
  39. Dim playerchips(1 To 11) As Double
  40. Dim stackheight As Integer
  41. Dim bottomy(1 To 11) As Integer
  42. Dim bottomx(1 To 11) As Integer
  43. Dim bottomx2(1 To 2) As Integer
  44. Dim bottomx3(1 To 2) As Integer
  45. Dim bottomx4(1 To 2) As Integer
  46. Dim CurrentPot As Double
  47. Dim colorcountplease As Integer
  48. Dim colorcountthree As Integer
  49. Dim memorycleaner As Integer
  50.  
  51. Private Sub SaveScreen(sPicFile As String)
  52.  
  53.     'This will capture the Entire Screen
  54.     Clipboard.Clear
  55. Sleep 1000
  56.     keybd_event vbKeySnapshot, 0, 0, 0
  57.     DoEvents
  58.     SavePicture Clipboard.GetData, "c:\screen.bmp"
  59.     DoEvents
  60.     Sleep 1000
  61. End Sub
  62.  
  63. Public Function LoadGraphicDC(sFileName As String) As Long
  64.  
  65. 'cheap error handling
  66. On Error Resume Next
  67.  
  68. 'temp variable to hold our DC address
  69. Dim LoadGraphicDCTEMP As Long
  70.  
  71. 'create the DC address compatible with
  72. 'the DC of the screen
  73. LoadGraphicDCTEMP = CreateCompatibleDC(GetDC(0))
  74.  
  75. 'load the graphic file into the DC...
  76. SelectObject LoadGraphicDCTEMP, LoadPicture(sFileName)
  77.  
  78. 'return the address of the file
  79. LoadGraphicDC = LoadGraphicDCTEMP
  80.  
  81. End Function
  82.  
  83. Private Sub SnapAndSave()
  84.  
  85.  
  86. DeleteObject myBufferBMP
  87. DeleteDC myBackBuffer   'clears the backbuffer
  88. DeleteDC mySprite   'this must be done after snap
  89.                     'is done and rgbval is retreived
  90.                     DoEvents
  91.  
  92. 'create a compatable DC for the back buffer..
  93. myBackBuffer = CreateCompatibleDC(GetDC(0))
  94.  
  95. 'create a compatible bitmap surface for the DC
  96. 'that is the size of our form.. (320 X 256)
  97. 'NOTE - the bitmap will act as the actua ' l graphics surface inside the DC
  98. 'because without a bitmap in the DC, the ' DC cannot hold graphical data..
  99.  
  100. myBufferBMP = CreateCompatibleBitmap(GetDC(0), 800, 600)
  101. 'final step of making the back buffer...
  102. 'load our created blank bitmap surface into our buffer
  103. '(this will be used as our canvas to draw-on off screen)
  104. SelectObject myBackBuffer, myBufferBMP
  105. 'before we can blit to the buffer, we should fill it with black
  106. BitBlt myBackBuffer, 0, 0, 800, 600, 0, 0, 0, vbWhiteness
  107. 'load our sprite (using the function we made)
  108.  
  109. SaveScreen "c:\" & Format(Now, "yyyymmddhhnnss") & ".bmp"
  110.  
  111. DoEvents
  112. mySprite = LoadGraphicDC("c:\pokerscreen.bmp")
  113. 'MsgBox Dir$(App.Path & "\sprite1.bmp")
  114. 'ok now all the graphics are loaded so
  115. 'lets start our main loop..
  116.  
  117. 'Disable cmdTest, because if the graphics are
  118. 'reloaded there will be memory leaks...
  119. 'Picture1.Enabled = False
  120. 'blit sprites to the back-buffer ***
  121. 'You could blit multiple sprites to the ' backbuffer,
  122. 'but in our example we only blit on...
  123. BitBlt myBackBuffer, Spritex, SpriteY, 800, 600, _
  124. mySprite, 0, 0, vbSrcPaint
  125. 'now blit the backbuffer to the form...
  126. 'BitBlt Me.hdc, 0, 0, 800, 600, myBackBuffer, _
  127. '0, 0, vbSrcCopy
  128.  
  129. 'rgbval = GetPixel(myBackBuffer, 526, 515)
  130. 'Label1.Caption = rgbval
  131.  
  132. 'move our sprite down on a diagonal...
  133. 'Me.Caption = SpriteX & ", " & SpriteY
  134. Spritex = 0
  135. SpriteY = 0
  136.  
  137. End Sub
  138.  
  139. Private Sub Timer1_Timer()
  140. Sleep 500
  141. SnapAndSave 'mybackbuffer is now full
  142. DoEvents
  143.  
  144. examinetable
  145.  
  146. End Sub
  147.  
  148. Private Sub examinetable()
  149.  
  150. Sleep 200
  151.  
  152. End Sub
  153.  
  154. Sub chipscan()
  155.  
  156.  
  157. bottomx(1) = 181
  158. bottomy(1) = 366
  159. bottomx(2) = 152
  160. bottomy(2) = 307
  161. bottomx(3) = 157
  162. bottomy(3) = 236
  163. bottomx(4) = 239
  164. bottomy(4) = 211
  165. bottomx(5) = 469
  166. bottomy(5) = 210
  167. bottomx(6) = 622
  168. bottomy(6) = 249
  169. bottomx(7) = 653
  170. bottomy(7) = 302
  171. bottomx(8) = 634
  172. bottomy(8) = 363
  173. bottomx(9) = 446
  174. bottomy(9) = 385
  175. bottomx(10) = 300
  176. bottomy(10) = 396
  177. bottomx(11) = 364
  178. bottomy(11) = 348
  179.  
  180.  
  181.  
  182. stackheight = 0
  183. Do
  184. stackheight = stackheight + 1
  185.  
  186. DoEvents
  187. playerchips(stackheight) = Round((fiftycentchips(stackheight) * 0.25) + (onedollarchips(stackheight)) + (fivedollarchips(stackheight) * 5) + (twentyfivedollarchips(stackheight) * 25), 2)
  188.  
  189. Loop Until stackheight = 11
  190.  
  191.  
  192. End Sub