I'm currently working on a user control, and I want to make the control appear transparent on any form is is placed. This line of thought lead me to try to obtain the background color of the form, pass it to the background color of my user control, and be done with it. Since I'm also using gradient coloring/bitmaps on the the form, I can't assume that the color of one location is going to work at a different location on the form. As a result, I figured that I would write a quick test app to try to use GetPixel from the parent.hDC and SetPixel on the usercontrol.

Unfortunately, I always get a CLR_INVALID from Get_Pixel and Set_Pixel regardless of which pixel I try to snag. Any ideas or suggestions for a better solution?
VB Code:
  1. Private Sub UserControl_TestSub()
  2.  
  3.     Dim lhWnd           As Long
  4.     Dim lDC             As Long
  5.     Dim lGetPixel       As Long
  6.     Dim lSetPixel       As Long
  7.    
  8.     lhWnd = GetParent(Me.hwnd)
  9.     lDC = GetDC(lhWnd)
  10.    
  11.     lGetPixel = GetPixel(lDC, 0, 0)
  12.     lSetPixel = SetPixel(Me.hdc, 0, 0, lGetPixel)
  13.    
  14.     Call SetPixel(Me.hdc, 0, 0, GetPixel(lDC, 0, 0))
  15.    
  16.     MsgBox lhWnd & " : " & Me.hwnd & " :: " & lDC & ": " & Me.hdc & " ::: " & lGetPixel & ", " & lSetPixel
  17. End Sub