Accessing Pixels on a PowerPoint Presentation

Greetings,
I need to create a simple Xojo app that will monitor a PowerPoint presentation (every 300ms) that is on another monitor and then launch some code when the color of a small box (20 pixels square) changes to a specific color. I understand how the timer functions, so I need information about how to grab the pixels on another screen and examine their values.

When I search the forum for info about this, most of the articles about grabbing pixels are very old, so I would like to know the most up-to-date way to do this and which Xojo features would be best. One of the challenges is that the PowerPoint presentation is on a separate monitor of a multi-monitor system, so the code needs to be able to access the appropriate screen.

Thanks in advance for your help - any guidance would be appreciated.

Don

Is the powerpoint displayed by another app ?

Yes, the powerpoint presentation is being displayed by Microsoft PowerPoint.

What you could do is to grab a screen shot, and then use RGBSurface pixel() to pick the appropriate pixel.

Sounds like a plan… does Xojo have a screen shot utility?

I briefly looked into RGBSurface and I think I can figure out that part.

MBS Picture Plugin should be able to do a screenshot for you.

1 Like

No need to buy plugins. You can do it with declares, there are lots of examples on the forum:

1 Like

Very good - I will give it a try. Thanks to all of you for your help.

Don

Okay - I’m back. My app is working, but I had to cheat to get the desired results. I shelled-out to a simple Python script that returned a single pixel and everything works from there. BTW, I’m no longer committed to selecting a different screen - the primary monitor will be just fine.

BUT, it takes a big toll on my CPU. So, I drilled into the Python app and found that it’s calling a WinApi called getPixelColor, which is calling a simpler api called “GetPixel”, which would solve all of my problems :grinning: This is the Python call: color = windll.gdi32.GetPixel(hdc, x, y)

Since finding this API, I’ve been studying and playing with the response from Ivan in this thread, trying to use Declares, etc. to call GetPixel for an x,y coordinate and return an RGB color that I can examine, but I have not had any success.

I would greatly appreciate it if someone could help me write a method that does the Declares and gets the device contexts and HDC’s, and whatever else is needed, since the world of API’s is quite foreign to me.

Thanks in advance for your help.
Don

Well, I came up with a solution by just playing around with an example. I am very unsure about what I was doing, but it works. I suspect there are unnecessary statements in the code below, but it’s a solution.

If you’re interested, my code is listed below. If you see any potential hazards (e.g. incorrectly releasing the DC) or unnecessary lines, I would love to hear about it.

Thanks again,
Don

#If TargetWindows Then
Declare Function GetDesktopWindow Lib “User32” () As Integer
Declare Function GetDC Lib “User32” (HWND As Integer) As Integer
Declare Function GetPixel Lib “gdi32” (DCdest As Integer, X As integer, Y As integer) as color
Declare Function ReleaseDC Lib “User32” (HWND As Integer, DC As Integer) As Integer

Dim pixel as Color
Dim HWND As Integer = GetDesktopWindow()
Dim SourceDC As Integer = GetDC(HWND)

pixel = GetPixel(SourceDC, xLoc, yLoc)
Call ReleaseDC(HWND, SourceDC)
Return pixel

#Endif