的GetDC(NULL)获取主显示器或虚拟屏幕? [英] GetDC(NULL) gets primary monitor or virtual screen?

查看:410
本文介绍了的GetDC(NULL)获取主显示器或虚拟屏幕?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

环顾净我看到大多数人认为的GetDC(NULL)将得到整个设备上下文的主要的监视器(一个与0,0在其左上角)。但是,我感觉大多数人都只是说,因为这是在MSDN页的GetDC的可能的会说。

不过,如果你看看下面的两页(至少两个)似乎是​​说的GetDC(NULL)返回覆盖整个的虚拟的屏幕(即包括一个设备上下文连接到系统的每一个显示器)。

(1)<一href=\"https://www.microsoft.com/msj/0697/monitor/monitor.aspx\">https://www.microsoft.com/msj/0697/monitor/monitor.aspx
- >搜索页面,这得到了虚拟桌面的RECT,并期待在周围位(上面特别的GetDC(NULL))该声明

(2)<一href=\"http://msdn.microsoft.com/en-gb/library/windows/desktop/dd162610%28v=vs.85%29.aspx\">http://msdn.microsoft.com/en-gb/library/windows/desktop/dd162610%28v=vs.85%29.aspx
- >搜索页面的GetDC(NULL)

我一直在试图找出它确实是,但冲突观点的众多击败我。

有没有人有这个任何真正的经验,可以测试它多显示器系统上? (我只有一个显示器,所以我不能。)

是否得到直流覆盖整个主监视器或DC覆盖了整个虚拟屏幕?

修改

对于任何想尝试一下,我的系统上,如果我创建一个默认的项目,并把下面是WinMain中它变成黑屏。如果您有多个显示器,你试试吧,问题就变成它变成只是你的主显示器的黑色或所有显示器?

  HDC HDC =的GetDC(NULL);
RECT R = {LONG_MIN,LONG_MIN,LONG_MAX,LONG_MAX};
FillRect(HDC,&放大器; R,(HBRUSH)(COLOR_BTNTEXT + 1));
ReleaseDC(NULL,HDC);


解决方案

它得到一个DC覆盖整个虚拟屏幕。我只是测试:

 的#include&LT;&WINDOWS.H GT;
#包括LT&;&CONIO.H GT;诠释主(){    HDC屏幕=的GetDC(NULL);    RECT R = {-1200,100,-200,500};
    HBRUSH BR = CreateSolidBrush(RGB(0,255,0));    FillRect(屏幕,和放大器; R,BR);    残培();
    InvalidateRect(NULL,&安培; R,真正的);    返回0;
}

...和它成功地吸取我的次级屏幕上的绿色矩形(定位到主屏幕的左侧,以便它具有负X坐标)。

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). However, I get the feeling most people are just saying that because that's what the msdn page for GetDC might be saying.

However, if you look at the following two pages (at least these two) seem to be saying that GetDC(NULL) returns a device context that covers the entire virtual screen (the one that encompasses every monitor attached to the system).

(1) https://www.microsoft.com/msj/0697/monitor/monitor.aspx -> search the page for "This gets the RECT of the virtual desktop" and look at the bits around that statement (particularly the GetDC(NULL) above it).

(2) http://msdn.microsoft.com/en-gb/library/windows/desktop/dd162610%28v=vs.85%29.aspx -> search the page for "GetDC(NULL)"

I have been trying to figure out which it really is, but the multitude of conflicting opinions defeats me.

Does anyone have any real experience of this, and can test it on a multimonitor system? (I only have one monitor so I can't.)

Does it get a DC covering the entire primary monitor OR a DC covering the entire virtual screen?

Edit

For anyone wanting to try it out, on my system, if I create a default project and put the following in WinMain it turns the screen black. If you have multiple monitors and you try it, the question becomes does it turn just your primary monitor black OR all your monitors?

HDC hdc = GetDC(NULL);
RECT r = {LONG_MIN, LONG_MIN, LONG_MAX, LONG_MAX};
FillRect(hdc, &r, (HBRUSH)(COLOR_BTNTEXT + 1));
ReleaseDC(NULL, hdc);

解决方案

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).

这篇关于的GetDC(NULL)获取主显示器或虚拟屏幕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆