Problems with GetPixel:( And skinnabal control

02-14-2005, 01:04 AM
helo, I have som code to loop throu all the pixels in my form, but everytime I call GetPixl I get -1 in return (CLR_iNVALID), and I have no idea what I must do to make it work...

Private Sub Form_Load()
Dim iX, iY As Long
Dim tempX, tempY
Dim CustRgn As Long
Dim MainRgn As Long
Dim lNumber, lNumber2 As Long
Dim meDC As Long
Dim lColor As Long
Me.Show ' Show form
Me.BackColor = vbWhite
Me.ScaleMode = 3 'Pixel...
iX = CLng(Me.ScaleX(Me.Width)) 'form width in pixels
iY = CLng(Me.ScaleY(Me.Height)) 'form height in pixels

MainRgn = CreateRectRgn(0, 0, iX, iY)
meDC = CreateCompatibleDC(Me.hdc)

lColor = GetPixel(meDC, 5, 5)
'loop the pixels...
For tempX = 0 To iX
For tempY = 0 To iY
lColor = GetPixel(meDC, tempX, tempY)
Debug.Print lColor
Next tempY
Next tempX
End Sub

any idea?
PS. from MSDN:
The return value is the RGB value of the pixel. If the pixel is outside of the current clipping region, the return value is CLR_INVALID.
what do they meen with current clipping region?

02-14-2005, 07:40 PM
Well, I'm not an expert in using DC's and the API, but while you've created a DC
compatible with your form "meDC = CreateCompatibleDC(Me.hDC)"
you haven't loaded it with anything or drawn on it, so GetPixel won't have anything to
read (as far as I know).
If you just want to read the pixels from the Form, you should just reference the hDC of
the form.

lColor = GetPixel(hdc, 5, 5)
'loop the pixels...
For tempX = 0 To iX - 1
For tempY = 0 To iY - 1
lColor = GetPixel(me.hDC, tempX, tempY)
Debug.Print Hex$(lColor)
Next tempY
Next tempX

Also note that I subtracted 1 from iX and iY since you are startin at 0 you need to
subtract 1 from the width and height.

And Current Clipping region means the area enabled for reading and writing in
your window. It's what keeps you from drawing outside the bounds of the
window. If you draw or bitblt to an area outside your window, the drawing
or blt is clipped at the edge of the Current Clipping Region (the borders of your window).
You can change the clipping region so that drawing occurs on only a portion
of your window, with the rest protected.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum