Cleaning Up Glass
All those bitmaps and device contexts in Create have to be cleaned up. The Destroy method (which is called by the Class_Terminate event procedure) provides a place where you can be sure that cleanup happens. Here’s the code:
Sub Destroy()
BugAssert fExist
‘ Select old mask back to DC
Call SelectObject(hdcMask, hbmpMaskOld)
‘ Now it’s safe to delete DC and bitmask
Call DeleteDC(hdcMask)
Call DeleteObject(hbmpMask)
‘ Clean up inverted image DC
Call SelectObject(hdcImage, hbmpImageOld)
Call DeleteDC(hdcImage)
Call DeleteObject(hbmpImage)
‘ Clean up cache DC
Call SelectObject(hdcCache, hbmpCacheOld)
Call DeleteDC(hdcCache)
Call DeleteObject(hbmpCache)
‘ Clean up old background DC
Call SelectObject(hdcBack, hbmpBackOld)
Call DeleteDC(hdcBack)
Call DeleteObject(hbmpBack)
xOld = -1: yOld = -1
fExist = False
End Sub