I know the following code essentially does nothing, it is meant solely for example purposes. My question is when you use the DeleteDC function does it destroy whatever objects are currently selected into it as well. I have read somewhere that you should restore the previous object to the DC when you are done performing whatever operation you are attempting to it, but what if you want to, say for example, change the Pen and leave it as it is, is it OK to use the DeleteObject function to get rid of the original Pen that was created with the DC??

Code:
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function CreatePen Lib "gdi32" (ByVal nPenStyle As Long, ByVal nWidth As Long, ByVal crColor As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long

Private Sub Form_Load()
 Dim lDC As Long
 Dim lPenNew As Long, lPenOld As Long
 Dim lRet As Long

 ' get handle to new dc
 lDC = CreateCompatibleDC(Me.hdc)
 ' get handle to new pen
 lPenNew = CreatePen(ps_solid, 1, vbRed)
 ' get handle to previous pen and select new pen into dc
 lPenOld = SelectObject(lDC, lPenNew)
 ' destroy old pen
 lRet = DeleteObject(lPenOld)
 ' destroy dc
 lRet = DeleteDC(lDC)
 
End Sub
??