Is there an API for redrawing a specific window from another application?

A customer had a Web-based full-screen application, and they wanted to write a companion application that did the following every second:

  • FindWindowInvalidateRectUpdateWindow, or

  • FindWindowRedrawWindow.

They wanted to know whether there was some other API for redrawing a window, because the mechanisms above have the side effect of causing the window to flicker.

This is a strange sort of request, so we asked the customer what they are trying to accomplish by triggering artificial redraws. After all, if the content didn't change, then there's no point in redrawing. And if the content did change, the Web page will redraw itself anyway. And the issue isn't that they want to F5-refresh the Web page, because a redraw doesn't trigger a page refresh. What's the use case for forcing a redundant redraw?

The customer explained that they are using a specific display monitor from a specific manufacturer, and they found that some of the monitors go to black if they display an unchanging image for more than a few minutes. These monitors are being used in public spaces where it is expected that the content may remain unchanged for an extended period of time. The customer is already working with the monitor manufacturer to investigate the problem, but they are looking for a workaround while the root cause investigation continues.

If you look at the problem that way, you'll see that even if they got the workaround they wanted, it wouldn't solve their problem! The problem is that the display monitor has a defect where it requires screen updates. They are looking for something that forces a screen update. They found something that forces a screen update, but it causes the screen to flicker. But what they don't realize is that the flicker is the screen update! If you perform a flickerless redraw, then no pixels on the screen will change, and then the monitors will go to black.

The customer doesn't realize it, but they want flicker, because it is the flicker that is keeping the monitors from going dark. They just want a tiny bit of flicker instead of an entire screen full of flicker, which is what they're getting now.

My recommendation is create a 1×1 window, show it on the screen for one second, and then remove it. Choose a corner of the screen, so it won't be too noticeable to the user. If the corner of the screen normally shows a white pixel, you might have your tiny pop-up window show a very light gray pixel, so that even if the user is watching for the flicker, it will be barely noticeable. (You'll have to experiment to see how much flicker is needed in order to keep the monitors from going black.) Show the window without taking focus so that the main application remains unaffected.

Don't go around trying to poke other applications' windows. If you want to update the screen, then update the screen.

Imagine you have a security camera that goes to sleep if nothing moves for five minutes. You have the security camera pointed at a giant ship that is docked and not moving. Redrawing the application window is like asking the ship to move forward a little bit, then move back. Much easier is to build a little machine that waves a stick in front of the camera. But what you definitely don't want to do is build an invisible stick.

Comments (26)
  1. henke37 says:

    They must have rather relaxed motion detection if they can get it to think that a ship isn’t moving.

  2. Mason Wheeler says:

    Invisible Waving Stick. That sounds like a rock band name…

  3. Adam says:

    Here’s a use case for wanting to do this exact thing. I own a window that embeds a child window owned by a helper process over its whole client area. If I add WS_THICKFRAME, Windows likes to draw over the borders when the window is activated or deactivated, despite my best efforts to return 0 from the WM_NCCALCSIZE handler or to use DwmExtendFrameIntoClientArea. My process’s window receives the WM_ACTIVATE message and WM_NCPAINT messages and I want to handle one of both of these by telling the child window to redraw part of itself because we can assume that Windows drew over the edge of the window.

    The biggest issue here is synchronization. Any functions that use SendMessage shouldn’t be used, which potentially rules out UpdateWindow. I settled on using InvalidateRect with a bErase parameter of FALSE to avoid flicker.

  4. Falcon says:

    I would love to know what could cause a monitor to do this – assuming the description of the symptom is correct.

    1. Many monitors come with some form of burn-in protection or auto-sleep functionality, especially if they comply with EnergyStar standards. Usually there’s an option in the monitor’s OSD menu that allows this to be disabled, but I’ve definitely encountered monitors that don’t.

      1. Falcon says:

        What threw me was the fact that some monitors did it and some didn’t. It sounds like they’re all identical models. I guess they might have just been configured differently.

        1. Cesar says:

          @Falcon: those who use third-party router firmware know well the tendency of manufacturers to completely change a device’s internals while keeping the same model number. I imagine it’s either that, or a difference in the monitor’s firmware version.

    2. Antonio Rodríguez says:

      I’m going to use my psychic powers. Being a public space, I would bet the monitor has some kind of plasma display (they are brighter and easier to read from odd angles than LCDs). Plasma displays are basically arrays of tiny CRTs, one subpixel pixel each (R, G or B), and like CRTs, they suffer from burn out. You can see this at airports and bus stations. Thus, the “defect” can be an anti-burn feature that switches off the display when an static image has been shown for too long.

  5. The MAZZTer says:

    Now I’m curious if the customer simply wasn’t aware of the Power Management settings in Windows which turn off your monitor after some time of inactivity. Or if it was a “feature” of the driver or monitor because they didn’t know how to properly implement standard sleep features…

  6. I was thinking of a similar answer… many years ago, I wrote a quick little app that would occasionally (every 30 seconds or so) adjust the mouse position by one px (and then back)… this would let me disable my screensaver while the app was running (in retrospect, a button to “enable/disable” would’ve been a nice enhancement)… same concept :)

  7. Eddie Lotter says:

    Apart from the “solving the wrong problem” issue, I have to question their chosen frequency. If the monitor is going dark after not being updated for more than a second then how did it even get shipped as a working product?

    1. DWalker says:

      I think you misread the story. It said “they found that some of the monitors go to black if they display an unchanging image for more than a few minutes”.

      1. Eddie Lotter says:

        The line “they wanted to write a companion application that did the following every second” is what I am calling out. It’s as if they think that unless they do it *every second* the monitor will go dark, which is ridiculous. Later in the article it is mentioned that they are aware that the monitor goes dark after a few minutes, so again I have to question their desired refresh frequency.

        1. DWalker says:

          I read it that the companion application that did “the following” every second was just to make sure that something got written so the monitor would not go dark.

          I question why the solution had to run every second, instead of every 30 seconds or so, but … whatever.

  8. EduardoS says:

    Such machine that makes a small move in intervals already exists, it is called a clock.

    And for the customers, it will be much less weird (I mean, not look like a bug) than a waving stick or a flashing pixel.

    1. Joshua says:

      Sanity has prevailed.

    2. Scarlet Manuka says:

      Kudos. A well conceived solution.

    3. Brian_EE says:

      >it is called a clock

      I think you missed from the original text: “Web-based full-screen application” and “being used in public spaces ”

      It’s a kiosk. And the browser is full-screen, so the clock is covered. And these are typically setup (at least one hopes) that users cannot access the taskbar/start-menu/those-funny-tile-things.

      What we know – they have control over the software loaded on the machine. We don’t know that they have any control over the web-based content (they could be just setting machines up under a contract for someone else). So rule out using JS to dynamically & periodically change the CSS on some small elements.

      1. Falcon says:

        I think they’re referring to Raymond’s analogy of waving a stick in front of a camera.

  9. AsmGuru62 says:

    When the solution is implemented – they will come back with:
    “Why do we have to replace burnt monitors so often?”

    1. I was thinking the same thing. It would make more sense if they made their content just dynamic enough that the screens don’t display identical content for hours at a time. At that rate, you might as well use posters instead (cheaper too).

  10. Tim! says:

    Invisible Stick would make a great band name

    1. Tim! says:

      Olde news is olde.

  11. Ray Koopa says:

    And I first thought it’s just the screen saver / power management kicking in when I read that their issue is a monitor going black.

  12. John says:

    Just make a gif of the company’s logo rotating, or morphing somehow, and stick it in the corner the web page you’re displaying. Problem solved.

  13. Andreas says:

    The stick has been used in real life, only it was a beckoning cat (“maneki-neko”). It was a fairly clever solution, and cute, too!

Comments are closed.

Skip to main content