|
-
Sep 15th, 2006, 12:54 PM
#1
Thread Starter
Hyperactive Member
[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:
Private Sub UserControl_TestSub()
Dim lhWnd As Long
Dim lDC As Long
Dim lGetPixel As Long
Dim lSetPixel As Long
lhWnd = GetParent(Me.hwnd)
lDC = GetDC(lhWnd)
lGetPixel = GetPixel(lDC, 0, 0)
lSetPixel = SetPixel(Me.hdc, 0, 0, lGetPixel)
Call SetPixel(Me.hdc, 0, 0, GetPixel(lDC, 0, 0))
MsgBox lhWnd & " : " & Me.hwnd & " :: " & lDC & ": " & Me.hdc & " ::: " & lGetPixel & ", " & lSetPixel
End Sub
-
Sep 15th, 2006, 01:02 PM
#2
Thread Starter
Hyperactive Member
Re: GetPixel/SetPixel Issue
 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:
UserCtrl.SetBgColor(GetPixel(Me.hDC,0,0)
-
Sep 15th, 2006, 06:49 PM
#3
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.
-
Sep 18th, 2006, 12:11 PM
#4
Thread Starter
Hyperactive Member
Re: GetPixel/SetPixel Issue
 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|