GetDC(NULL) gets primary monitor or virtual screen?

前端 未结 2 1175
清酒与你
清酒与你 2020-12-17 20:16

Looking around the net I see that most people think that GetDC(NULL) will get a device context for the entire primary monitor (the one with 0,0 at its top left). Ho

相关标签:
2条回答
  • 2020-12-17 21:02

    It gets a DC that covers the entire virtual screen. I just tested with:

    #include <windows.h>
    #include <conio.h>
    
    int main() {
    
        HDC screen = GetDC(NULL);
    
        RECT r = {-1200, 100, -200, 500};
        HBRUSH br = CreateSolidBrush(RGB(0, 255, 0));
    
        FillRect(screen, &r, br);
    
        getch();
        InvalidateRect(NULL, &r, true);
    
        return 0;
    }
    

    ...and it successfully draws a green rectangle on my secondary screen (positioned to the left of the primary screen so it has negative X coordinates).

    0 讨论(0)
  • 2020-12-17 21:04

    I'm currently trying to rewrite a gamma setter utility, because it is using GetDC(NULL) instead of EnumDisplayMonitors + GetDC, and as a result, changes the gamma of the entire desktop.

    Your program is similar, it paints both displays black.

    0 讨论(0)
提交回复
热议问题