-1

I am trying to read multiple pixel using GDI plus python APIs. As the screen portion I am reading, is very small, while copying the screen to memory device context, I am consider only that particular portion.

As I am polling continuously, and comparing the new screen with old screen, it is causing high CPU usage. So I am wondering is there any efficient way to read the screen only when screen is updated ?

Rahul
  • 1,607
  • 3
  • 23
  • 41
  • The easiest thing would be to call sleep after each comparision. That way CPU usage would drop dramatically. It's probably fest enough to have sa 50 comparisions pers second rather than say 1000. – Jabberwocky Dec 20 '17 at 07:26
  • @MichaelWalz as our screen is continuously getting updated, so if I use sleep, it might miss the information. that's why I am looking for push based mechanism. – Rahul Dec 20 '17 at 07:56

1 Answers1

0

If you know the update action you are interested in occurs during WM_PAINT you could install a windows hook (either a CallWndProc or CBTProc hook) and perform your action after dispatching the WM_PAINT to the window of interest.

SoronelHaetir
  • 14,104
  • 1
  • 12
  • 23
  • I have another thread in a different process which is writing some data on the windows and calling update() function. And read code is independent of the write thread, so I am not sure if I can try your approach. – Rahul Dec 20 '17 at 11:18
  • 2
    @Rahul: That's a pretty broken design right there. Do not ever try to render from a thread other than the thread owning a window. This is true for pretty much any GUI library. – IInspectable Dec 20 '17 at 11:38