'放一个按钮,一个PictureBoxOption Explicit Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As LongPrivate Sub Command1_Click() Dim i As Long, j As LongBitBlt Picture1.hdc, 0, 0, 800, 600, GetDC(0), 0, 0, vbSrcCopy Picture1.Refresh For i = 0 To 599 For j = 0 To 799 If GetPixel(Picture1.hdc, j, i) = &HFF Then MsgBox "X=" & j & " Y=" & i Exit Sub End If Next Next End SubPrivate Sub Form_Load() Picture1.AutoRedraw = True Picture1.ScaleMode = 3End Sub
再简单一点 Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As LongPrivate Sub Command1_Click() Dim i As Long, j As Long Dim dc As Long dc = GetDC(0) For i = 0 To 599 For j = 0 To 799 If GetPixel(dc, j, i) = &HFF Then MsgBox "X=" & j & " Y=" & i Exit Sub End If Next Next End Sub
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As LongPrivate Sub Command1_Click()
Dim i As Long, j As LongBitBlt Picture1.hdc, 0, 0, 800, 600, GetDC(0), 0, 0, vbSrcCopy
Picture1.Refresh
For i = 0 To 599
For j = 0 To 799
If GetPixel(Picture1.hdc, j, i) = &HFF Then
MsgBox "X=" & j & " Y=" & i
Exit Sub
End If
Next
Next
End SubPrivate Sub Form_Load()
Picture1.AutoRedraw = True
Picture1.ScaleMode = 3End Sub
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As LongPrivate Sub Command1_Click()
Dim i As Long, j As Long
Dim dc As Long
dc = GetDC(0)
For i = 0 To 599
For j = 0 To 799
If GetPixel(dc, j, i) = &HFF Then
MsgBox "X=" & j & " Y=" & i
Exit Sub
End If
Next
Next
End Sub