Results 1 to 6 of 6

Thread: [resolved] Test Colour

  1. #1

    Thread Starter
    Addicted Member Jazz00006's Avatar
    Join Date
    Feb 2006
    Posts
    185

    Resolved [resolved] Test Colour

    hey me again ...


    I got this code... All mine
    VB Code:
    1. Public Function TestColor(Colortest As Long) As String
    2. Dim X As Long, Y As Long, test As Long, wndrect As RECT
    3. GetWindowRect selWnd, wndrect
    4. test = GetDC(selWnd)
    5. TestColor = false
    6. For Y = 0 To (wndrect.Bottom - wndrect.Top)
    7.   For X = 0 To (wndrect.Right - wndrect.Left)
    8.    If GetPixel(test, X, Y) = Colortest Then
    9.       TestColor = true
    10.       Exit Function
    11.       Exit Function
    12.     End If
    13.   Next X
    14. Next Y
    15. End Function


    but when i type in

    if testcolor(255)=true then msgbox "Found it"


    if doesnt find it... but if i put in false it does find it....

    I know there is a color 255 on my screen but it all screws up....

    ive tried reversin the true and false statements but it still works in reverse....

    any help?
    Last edited by Hack; Mar 3rd, 2006 at 07:25 AM.

  2. #2
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: Test Colour

    You should return a boolean, and you don't need 2 exit function
    VB Code:
    1. Public Function TestColor(Colortest As Long) As Boolean
    2. Dim X As Long, Y As Long, test As Long, wndrect As RECT
    3. GetWindowRect selWnd, wndrect
    4. test = GetDC(selWnd)
    5. TestColor = false
    6. For Y = 0 To (wndrect.Bottom - wndrect.Top)
    7.   For X = 0 To (wndrect.Right - wndrect.Left)
    8.    If GetPixel(test, X, Y) = Colortest Then
    9.       TestColor = true
    10.       Exit Function
    11.     End If
    12.   Next X
    13. Next Y
    14. End Function

  3. #3

    Thread Starter
    Addicted Member Jazz00006's Avatar
    Join Date
    Feb 2006
    Posts
    185

    Re: Test Colour

    ok let me rephrase that... When i say to find something it wont find it .. eg returen false
    even if it is true it just wont find it ... ?!?!

  4. #4
    Frenzied Member d3gerald's Avatar
    Join Date
    Jan 2006
    Posts
    1,348

    Re: Test Colour

    maybe this revision of mine could help

    VB Code:
    1. Public Function TestColor(Colortest As Long) As Boolean
    2.     Dim X As Long, Y As Long, test As Long, wndrect As RECT
    3.     GetWindowRect selWnd, wndrect
    4.     test = GetDC(selWnd)
    5.     For Y = 0 To (wndrect.Bottom - wndrect.Top)
    6.         For X = 0 To (wndrect.Right - wndrect.Left)
    7.             If GetPixel(test, X, Y) = Colortest Then
    8.                 TestColor = true
    9.                 Exit Function
    10.             End If
    11.         Next
    12.     Next
    13.     TestColor = false
    14. End Function
    On error goto Trap

    Trap:
    in case of emergency, drop the case...

    ****************************************
    If this post has been resolved. Please mark it as "Resolved" by going through the "Thread Tools" above and clicking on the "Mark Thread Resolved " option.
    if a post is helpful to you, Please Rate it by clicking on the Rate link right below the avatar

  5. #5
    Addicted Member LeonX's Avatar
    Join Date
    Dec 2004
    Location
    Jakarta, Indonesia
    Posts
    172

    Re: Test Colour

    i think a pixel is in form of RGB like this &HFFFFFF, which the middle byte is Green, and the left byte is either Red or Blue (sorry forget the sequence)
    if you want to compare 255 (i consider you want to compare a white pixel) you should compare with &HFFFFFF rather than 255 decimal.
    Regards,
    Ferry

  6. #6

    Thread Starter
    Addicted Member Jazz00006's Avatar
    Join Date
    Feb 2006
    Posts
    185

    Re: Test Colour

    LOL i found out what the problem was...
    i feel so ashamed


    when i selected the current window it would find it fine... but when i said find colour then clicked on play it would only do it in the selected window... so i just made it go on a hotkey.. and it worked..


    thanks to you all for your help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width