views:

47

answers:

1

We want to create a Windows desktop version of our weather widget

There are 2 special things about the widget.

  1. It consumes a lot of processor time while active - it displays an animated picture (Flash without GPU acceleration, unfortunately).
  2. It updates the weather from our server (frequent server requests from all widget users).

When the user does not look at the widget there is no need for animation and weather loading.

So I have an idea of putting my widget to sleep when it is not visible and hense not used.

Is it possible to detect whether the widget is used or not. Speaking precisely I need to know whether the widget is covered by other windows?

I mostly interested in Vista/7 gadgets engine, however I also would like to know if this problem is solved in these widget engines

  • Yahoo widgets
  • Google desktop

Hope to find some desktop widget guru here.

Pasha

+1  A: 

If you InvalidateRect and don't get a subsequent WM_PAINT message, than your window is hidden. You can call UpdateWindow after InvalidateRect to force the WM_PAINT message to happen (or not happen) right away.

So you could do something like this

  1. request server data (and cancel request timer if any)
  2. when data arrives InvalidateRect
  3. when WM_PAINT message arrives, draw the data and set a timer for next request
  4. when timer arrives, goto 1

When you stop getting WM_PAINT messages, you stop re-setting your timer, and you therefor stop requesting updates from the server. When the WM_PAINT message happens (because you are no longer covered). You start requesting data again.

John Knoeller
Doesn't work with Aero enabled, windows never overlap since they are rendered in an off-screen memory buffer.
Hans Passant