|
-
Jun 22nd, 2006, 09:52 AM
#1
Thread Starter
Frenzied Member
Problem with GetPixel - help please
The routine I have below I want to get the pixel of the screen. It returns nothing here. If I move the GetPixel call out of the loop, it returns something.
Any idea what I'm doing wrong or a better way of this?
Thanks!
VB Code:
Private Sub Command1_Click()
Dim hDC As Long
Dim H1 As Long
Dim W1 As Long
Dim Z As Long
H1 = Screen.Height / Screen.TwipsPerPixelY
W1 = Screen.Width / Screen.TwipsPerPixelX
Dim X As Long
Dim Y As Long
hDC = GetDC(0) 'get desktop dc
For Y = 1 To Y1 - 10
For X = 1 To H1 - 10
Z = GetPixel(hDC, X, Y)
Memo1.Text = Memo1.Text & Trim(Str(Z))
Next X
Next Y
End Sub
-
Jun 22nd, 2006, 10:07 AM
#2
Re: Problem with GetPixel - help please
you're using Y1 rather than W1 (or whatever it should be) in the first For - use Option Explicit at the top of the form to catch these errors!
-
Jun 22nd, 2006, 12:31 PM
#3
Addicted Member
Re: Problem with GetPixel - help please
Also, when using GetDC(), you need to use ReleaseDC() when you're done with the DC. That allows the DC to be used again.
VB Code:
Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
'ex. in your sub, when you're done with the DC
Call ReleaseDC(Me.hwnd, hdc)
Last edited by Keith_VB6; Jun 22nd, 2006 at 12:32 PM.
Reason: forgot the [vbcode]
Keith_VB6
If you have any further questions, just ask.
If this solves things, then please mark the thread resolved.
[Thread Tools] --> [Mark Thread Resolved]
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
|