Results 1 to 13 of 13

Thread: Help!! Is it possible to send a messagebox if a certain color is detected on screen?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2000
    Posts
    1,195

    Help!! Is it possible to send a messagebox if a certain color is detected on screen?

    Anyone know of a program, or how to make a program that will monitor the users screen and send a message box when a certain color is detected?

  2. #2
    Frenzied Member seoptimizer2001's Avatar
    Join Date
    Apr 2001
    Location
    Toledo, Ohio USA GMT -5
    Posts
    1,075
    Do you mean just when a VB apps backcolor is a certain color, or anything on the screen. If it is the latter, I would assume there would have to be some pretty fancy API code.

  3. #3
    Frenzied Member
    Join Date
    Mar 2001
    Location
    You are HERE •™
    Posts
    1,300
    Look into the GetPixel and SetPixel API:

    http://www.vbapi.com/ref/g/getpixel.html
    http://www.vbapi.com/ref/s/setpixel.html

    The example code for setpixel goes through every pixel on a form and randomly changes the color.
    I'm sure you could adapt this code to check every pixel for a certain color instead.

  4. #4
    Frenzied Member Microbasic's Avatar
    Join Date
    Mar 2001
    Posts
    1,402
    Try this code. VB kept on crashing lately, so I couldn't debug it:

    FORM CODE:
    VB Code:
    1. Function NotifyonColor(Color As OLE_COLOR) As Boolean
    2.   Dim Colored as Long, X as long, Y as long, MaX as Long, MaY As long, temp as boolean
    3.   If OLE_COLOR > &H79999999 Then Colored = GetSysColor(OLE_COLOR - &H80000000) Else Colored = Color
    4.   max = me.scalex(screen.width, 1, 3)
    5.   may = me.scaley(screen.height, 1, 3)
    6.   for x = 0 to max
    7.     for y = 0 to may
    8.       if getpixel(getdc(0)) = Colored then
    9.         temp = True
    10.         Exit For
    11.       End if
    12.     next
    13.   next
    14.   NotifyonColor = temp
    15. End Sub

    MODULE CODE:
    VB Code:
    1. Public Declare Function GetDC Lib "user32" Alias "GetDC" (ByVal hwnd As Long) As Long
    2. Public Declare Function GetPixel Lib "gdi32" Alias "GetPixel" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
    3. Public Declare Function GetSysColor Lib "user32" Alias "GetSysColor" (ByVal nIndex As Long) As Long


    MicroBasic
    Dragon Shadow Trainer

    There is no good or evil in the world...only programmers and fools .

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2000
    Posts
    1,195
    cant get it to work..

  6. #6
    Well, could you be more clear first? Do you want to know if at least one pixel on the screen is, say, pure red? (#FF0000 or 255 0 0) Or a pixel at a certain location?

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2000
    Posts
    1,195
    well, i want it to monitor the screen and when the color (RGB: 16,248,0) is found, i get a messagebox informing me..

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2000
    Posts
    1,195
    anyone know how to do this?

  9. #9

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2000
    Posts
    1,195
    up

  10. #10
    Frenzied Member Microbasic's Avatar
    Join Date
    Mar 2001
    Posts
    1,402
    VB Code:
    1. Option Explicit
    2. Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
    3. Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
    4. Private Declare Function GetSysColor Lib "user32" (ByVal nIndex As Long) As Long
    5.  
    6. Function NotifyonColor(Color As OLE_COLOR) As Boolean
    7.   Dim Colored As Long, x As Long, y As Long, MaX As Long, MaY As Long, temp As Boolean
    8.   If Color > &H79999999 Then Colored = GetSysColor(Color - &H80000000) Else Colored = Color
    9.   MaX = Me.ScaleX(Screen.Width, 1, 3)
    10.   MaY = Me.ScaleY(Screen.Height, 1, 3)
    11.   For x = 0 To MaX
    12.     For y = 0 To MaY
    13.       If GetPixel(GetDC(0), x, y) = Colored Then
    14.         temp = True
    15.         Exit For
    16.       End If
    17.     Next
    18.   Next
    19.   NotifyonColor = temp
    20. End Function
    21.  
    22. Private Sub Form_Load()
    23.     If NotifyonColor(&HC0C0C0) = True Then MsgBox "*"
    24. End Sub


    MicroBasic
    Dragon Shadow Trainer

    There is no good or evil in the world...only programmers and fools .

  11. #11
    That code will probably take a year to execute, especially on higher resolutions, but short of using something like DirectX there is probably little you can do about it.

  12. #12
    Originally posted by qpabani
    well, i want it to monitor the screen and when the color (RGB: 16,248,0) is found, i get a messagebox informing me..
    Just because Filburt is bored right now , why do you want to do this? What will your program do in the end?

  13. #13

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2000
    Posts
    1,195
    just need it as a trade enchancement in diablo2, so when i get a message (which will be in green) a messagebox will show so i know i received a message.

    however, your code wont work

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