Link to home
Start Free TrialLog in
Avatar of Paranormal
Paranormal

asked on

Auto Rolling

Hey Experts,

I was wondering if you could make a VB program which would check an outside application on specific pixles to check the colour.

Like:

If ....... = blue Then
    End
Else
   Roll

Where the "......" would specific a particular region of pixels to see if they were blue (or some of them). If not then there is a button on the outside application that needs to be clicked (Roll). And that will be looped.

Seeing it in my head it shouldn't be all that hard, but i have no clue on how to get a program to check something from another program that isn't part of it.

p.s. If you really don't get what i mean i can try to explain it better, or i'll make an attempt too....

Avatar of DarkoLord
DarkoLord
Flag of Slovenia image

Hi, try this:

Private Declare Function GetDC Lib "user32" Alias "GetDC" (ByVal hwnd As Long) As Long
Private Declare Function GetPixel Lib "gdi32" Alias "GetPixel" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long

Sub Form_Load()
    Dim lDC As Long, lhWnd As Long, lPixel As Long
    lhWnd = 'put hwnd of an outside control here (you can use FindWindow API to find it)
    lDC = GetDC(lhWnd)
    lPixel = GetPixel(lDC, 1, 1)
    MsgBox lPixel
End Sub

Darko
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Paranormal
Paranormal

ASKER

Thanks a lot, i'm not done yet tho, i was wondering if i could make a command button, to make it run ofcourse and where i can put in the statements.

Private Sub Command1_Click()
If coordinates: 130, 340 = colour: 235, 234, 24 Then
   clickPoint
Else
    End
End Sub

I know i didn't write it all VB-like but thats because i wouldn't know how, while still making it understandable. And on top of this, can you make a region, like between (coordinates) 130, 340 and 140, 300 and then have em check every coordinate point inbetween to look if it has that specific pixel color?
Below are the two examples you asked for...the first checks the specific pixel and the second checks the entire region.  You could place the code in the second example in the timer event if you want it to repeat.

Private Sub Command1_Click()
    Dim pixelcolor As Long
    Dim red As Byte
    Dim green As Byte
    Dim blue As Byte
   
    pixelcolor = GetPixel(desktopDC, 130, 340)
       
    red = pixelcolor Mod &H100
    pixelcolor = pixelcolor \ &H100
    green = pixelcolor Mod &H100
    pixelcolor = pixelcolor \ &H100
    blue = pixelcolor Mod &H100
   
    If red = 235 And green = 234 And blue = 24 Then
        clickPoint 500, 250 ' <----- change these coordinates to where you want to click
    Else
        ' not sure what you mean by end here
    End If
End Sub

Private Sub Command2_Click()
    Dim pixelcolor As Long
    Dim x As Single
    Dim y As Single
    Dim red As Byte
    Dim green As Byte
    Dim blue As Byte
   
    ' between (coordinates) 130, 300 and 140, 340
    For x = 130 To 140
        For y = 300 To 340
            pixelcolor = GetPixel(desktopDC, x, y)
       
            red = pixelcolor Mod &H100
            pixelcolor = pixelcolor \ &H100
            green = pixelcolor Mod &H100
            pixelcolor = pixelcolor \ &H100
            blue = pixelcolor Mod &H100
   
            If red = 235 And green = 234 And blue = 24 Then
                clickPoint 500, 250 ' <----- change these coordinates to where you want to click
                Exit Sub
            End If
        Next y
    Next x
End Sub
Thank you for all that you showed me and gave me, it's still hard trying to mix it with the actual application i wanted to test it on but at least i got the basics and i believe i can figure the rest out myself,

Thank you very much.