Private Declare Function CreateDC Lib "GDI32" Alias "CreateDCA" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, ByVal lpInitData As String) As Integer
Private Declare Function CreateCompatibleDC Lib "GDI32" (ByVal hDC As Integer) As Integer
Private Declare Function CreateCompatibleBitmap Lib "GDI32" (ByVal hDC As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer) As Integer
Private Declare Function GetDeviceCaps Lib "GDI32" (ByVal hDC As Integer, ByVal nIndex As Integer) As Integer
Private Declare Function SelectObject Lib "GDI32" (ByVal hDC As Integer, ByVal hObject As Integer) As Integer
Private Declare Function BitBlt Lib "GDI32" (ByVal srchDC As Integer, ByVal srcX As Integer, ByVal srcY As Integer, ByVal srcW As Integer, ByVal srcH As Integer, ByVal desthDC As Integer, ByVal destX As Integer, ByVal destY As Integer, ByVal op As Integer) As Integer
Private Declare Function DeleteDC Lib "GDI32" (ByVal hDC As Integer) As Integer
Private Declare Function DeleteObject Lib "GDI32" (ByVal hObj As Integer) As Integer
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Private Const SRCCOPY As Long = &HCC0020
Private Sub FindColor(ByVal MyColor As Integer)
-> Dim Spic As Picture1.Picture
Spic = CaptureScreen.GetScreen()
'capture the screen to a image
For i = 0 To Spic.Width - 1
For k = 0 To Spic.Height - 1
'itterate through each pixel
If ColorTranslator.ToOle(Spic.GetPixel(i, k)) = MyColor Then
'if the pixel is the same color we are looking for
SetCursorPos = i & k
'exit the routine to save time
Exit Sub 'maybe get rid of this line if you want to other pixels too
End If
Next
Next
End Sub
Public Function GetScreen()
Dim oBackground As String
Dim FW, FH As Integer
Dim hSDC, hMDC As Integer
Dim hBMP, hBMPOld As Integer
Dim r As Integer
hSDC = CreateDC("DISPLAY", "", "", "")
hMDC = CreateCompatibleDC(hSDC)
FW = GetDeviceCaps(hSDC, 8)
FH = GetDeviceCaps(hSDC, 10)
hBMP = CreateCompatibleBitmap(hSDC, FW, FH)
hBMPOld = SelectObject(hMDC, hBMP)
r = BitBlt(hMDC, 0, 0, FW, FH, hSDC, 0, 0, 0)
hBMP = SelectObject(hMDC, hBMPOld)
r = DeleteDC(hSDC)
r = DeleteDC(hMDC)
oBackground = Picture1.Picture(hBMP)
DeleteObject (hBMP)
End Function
Private Sub Command1_Click()
Dim SearchColor As Integer
SearchColor = vbBlack
FindColor (SearchColor)
End Sub