Results 1 to 4 of 4

Thread: [RESOLVED] GetPixel/SetPixel Issue

  1. #1

    Thread Starter
    Hyperactive Member Fedhax's Avatar
    Join Date
    Aug 2006
    Posts
    293

    Resolved [RESOLVED] GetPixel/SetPixel Issue

    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

  2. #2

    Thread Starter
    Hyperactive Member Fedhax's Avatar
    Join Date
    Aug 2006
    Posts
    293

    Re: GetPixel/SetPixel Issue

    Quote Originally Posted by Fedhax
    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?
    I forgot that GetPixel will only work on visible objects which means it won't work until the form is visible. However, is there any other way for the user control to know what kind of color it should be beside some kind of hack after the form has loaded?

    VB Code:
    1. UserCtrl.SetBgColor(GetPixel(Me.hDC,0,0)

  3. #3
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: GetPixel/SetPixel Issue

    why not set the Backstyle property of the usercontrol to transparent?
    Then you can use the maskpicture and maskcolor properties if you want to.

  4. #4

    Thread Starter
    Hyperactive Member Fedhax's Avatar
    Join Date
    Aug 2006
    Posts
    293

    Re: GetPixel/SetPixel Issue

    Quote Originally Posted by moeur
    why not set the Backstyle property of the usercontrol to transparent?
    Then you can use the maskpicture and maskcolor properties if you want to.
    Yeah, there was a reason that I wasn't using those properties, but as I thought about it, I simplified my control design so that these properties would work for me.

    (And, since I'm still relatively new to creating custom controls, I sometimes forget that this kind of built-in functionality is there. )

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width