View Full Version : GetPixel/SetPixel question


overflow
04-06-2004, 09:11 AM
Hi.

I'm tring to set a pixel color to red on a form when the detail area is clicked by using the getpixel and setpixel api, but have been unsuccessful as yet. I'm getting a -1 for both getpixel and setpixel which leads me to think that I'm not referencing something properly. Here's the code. Any suggestions? Thanks.




Option Compare Database
Private Type POINTAPI
x As Long 'x coordinate of the mouse
y As Long 'y coordinate of the mouse
End Type
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Declare Function SetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As Long


Private Sub Detail_Click()

Dim pp As POINTAPI
Dim i As Long

GetCursorPos pp
i = GetPixel(GetDC(GetDesktopWindow), pp.x, pp.y) ' -1 returned
i = SetPixel(GetDC(GetDesktopWindow), pp.x, pp.y, 255) ' -1 returned


End Sub

ghudson
04-06-2004, 11:07 AM
Not sure about your pixel problem but you can use color constants for simply changing the color of an object. This bit shows how to use the OnClick event of the details section of a form to change the color to red...Private Sub Detail_Click()

Me.Detail.BackColor = vbRed

End Sub
Check Color Constants in the help files for the other color options.

overflow
04-06-2004, 01:14 PM
Thanks.

I'm playing around with a few different things now. I was able to figure out my originial problem. I should have called GetDC(0) instead of GetDC(GetDesktopWindow).