Create program that outputs sound based on color in a windowed program

Hey coders out there, I am in need of a little help today! I am trying to find a program and or create one I guess (If I know how) that will allow me to record continously an application window of a program running on my computer and check to see if a color shows up in the designated region I have selected for that current program.

I guess this is how I want it to run:

1: Select region of a program that is open and set it
2: that region is monitored by my application and constantly checks to see if a certain ‘color’ RBG comes up
3: If that color I have selected happens to pop up on that screen then it plays a sound from a folder on the computer through my speakers

I am having a hard time explaning this but its similar to this program

I want the program to monitor a certain portion of an application running behind all my other windows really rather than it monitoring a single pixel on my screen.

Please note that the program running in the background will not be changing in window size nor will it move if that makes it any easier. The spot im recording will stay within the same pixel box if that makes sense…

Thanks guys!

Essentially, you’d like a program that monitors a portion of your screen and if a certain color (as in a single pixel) appears anywhere in that monitored portion, than the program will play some predetermined sound, yes?

I’m just trying to make sure I understand what you’d like.

That is correct… But i want it to follow a specific program rather than the screen as a whole because i will be doing other tasks along with it

Ahh, but will the specific program that it’s monitoring be the top most window? Or is that specific program going to be behind other windows occasionally?

I am hoping that i can have it be behind other windows but if it’s a must i can have it on top… Really hoping it can be behind other windows

I’d start with Win32’s PrintWindow function:

That’ll let you take a screenshot of a given window - even if it’s minimized (use Google to figure out how to call it).

If you go that route, you’ll have to call the function in a loop and risk missing some color changes (the ones that happen in-between the screenshot calls). If you need something near real-time, you’ll have to do some low-level hooking into the GDI library to detect when a window redraws itself. But even then you won’t be able to detect every change.

If PrintWindow fails, try the WM_PRINT and WM_PRINTCLIENT window messages.

The time just needs to be within a second or two so real time checking isnt a problem… I guess ill have to research more haha… How would i call to check for a color in a specific region of a printwindow picture then?

So I’m guessing my coding process should look like this somewhat

1: use printwindow to capture window
2: Check the captured window to see if my color is being projected in the region
3: a: if yes, play sound
b: if no, repeat loop

Thanks for the help guys!

That’s about all you have to do. You just have to find the region in the returned bitmap that you’re monitoring. The returned image should be an array of RGB color values (not 100% sure of this).

So I was able to get it to work up to a certain point. Now ill need a little guidance again as google couldn’t help.

I have the image in a picturebox (exactly what I wanted) when I load my program… Sadly, I want to be able to find a specific color inside that picturebox but I cannot figure out a way to do that.

I currently have been messing around with this:

 'Picture is on the picturebox. Now we need to FIND the specific color we are looking for......
        Dim bmp As New Bitmap(PictureBox1.Image)
        Dim b(bmp.Width * bmp.Height - 1) As Integer
        Dim bd As BitmapData = bmp.LockBits(New Rectangle(Point.Empty, bmp.Size), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb)
        Marshal.Copy(bd.Scan0, b, 0, b.Length)
        'This is where we check each pixel to see if it's yellow.
        Dim x As Integer = -1, y As Integer = -1
        For i As Integer = 0 To b.Length - 1
            If b(i) = Color.Yellow.ToArgb Then
                x = i Mod bmp.Width
                y = i \ bmp.Width
                Exit For
            End If
        'Display the results.
        If x > -1 Then
            MessageBox.Show("Found the yellow.")
            MessageBox.Show("No yellow found.")
        End If

Notice how it’s searching for a specific COLOR as in Color.Yellow… I either need it to search for an RGB or a hexadecimal color, not a generic one. How would I go about doing this? Ive been looking all over and cannot find any ways to fix this.


Color.FromArgb should do it. If your color is 0xFFEEDD: R=0xFF, G=0xEE, B=0xDD