C++ Drawing directly to the screen (like an overlay)
Asked Answered
Z

1

11

Many laptops nowadays have FN hot keys to change volume, brightness, etc. and usually display a visual cue that is rendered on the screen completely above the operating system. For new Windows 8/8.1 systems this visual even appears outside of the desktop in the metro side. They cannot be drawing inside of a borderless window otherwise it wouldn't show up over the metro interface.

I have tried researching whether DirectX can draw directly to the screen but it doesn't appear it can. I don't even know if I should look into OpenGL... ?

I had some success using GDI; specifically the GetDC function with the parameter NULL to grab the screen device.

#include <Windows.h>

int main() {
    const HDC dc = GetDC(NULL);
    while (1) {
        Rectangle(dc, 100, 100, 500, 500);
    }
}

However, this requires re-rendering everything repeatedly because my region of the screen can be overwritten by other windows changing in the background. And even with it re-rendering in a loop, there is massive screen flicker.

How do the OEM manufacturers of these laptops achieve this?

Thanks.

Zechariah answered 29/7, 2014 at 21:14 Comment(6)
i would check shell functionality. note that rendering directly to screen can produce lots of visual artifacts (due to some broken assumptions).Sampler
Try Windows Presentation Foundation (WPF). It can be used to draw 2D/3D graphics hovering over the desktop or any background.Sitra
Surely the Metro interface also uses the window manager at its core? If you can just get a hold of the right window station / desktop handle, I'm sure it's possible to show windows there as well. What user account does the vendor's overlay process run under (system account or your own)?Nucellus
DirectX and OpenGL won't help, since in windowed mode they're essentially using GDI. With GDI you can use WS_EX_TOPMOST flag when creating a window to keep it on top of all other windows, but I have no idea whether this would work on Windows 8 to draw stuff over the Metro interface.Eosinophil
How does linkCamStudio record the desktop? Maybe there's your mechanism?Bronson
take a good look into the extended window-creation options, perhaps some combination of WS_EX_TRANSPARENT (no-input magic!) may be what your looking for: #6165636Lurid
P
2

It looks like these are borderless windows. For example, have a look at the task switcher window:

Borderless Window

Related question: Windows 8 Layered Windows Over Metro Apps

If you want a window on top of Metro, you need it to declare accessibility.

Pteropod answered 14/7, 2015 at 15:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.