获取显示器的数量和分辨率

版权声明:本文为博主原创文章,未经博主同意不可随意转载。 https://blog.csdn.net/hellokandy/article/details/81013774

通过GetSystemMetrics 的几个重要参数,就可以获取显示器的数量、当前屏幕分辨率,以及总分辨率:

#include "stdafx.h"
#include <Windows.h>
#include <stdio.h>

int _tmain(int argc, _TCHAR* argv[])
{
	//当前屏幕的分辨率
	int nScreenWidth, nScreenHeight;
	nScreenWidth = GetSystemMetrics(SM_CXSCREEN);
	nScreenHeight = GetSystemMetrics(SM_CYSCREEN);

	printf("当前屏幕的分辨率为:%d×%d", nScreenWidth, nScreenHeight);

	getchar();

	//当前屏幕数量
	int screenNum;
	screenNum = GetSystemMetrics(SM_CMONITORS);
	printf("当前屏幕数量:%d\n", screenNum);

	getchar();

	//当前屏幕总的分辨率
	int aScreenWidth, aScreenHeight;
	aScreenWidth = GetSystemMetrics(SM_CXVIRTUALSCREEN);
	aScreenHeight = GetSystemMetrics(SM_CYVIRTUALSCREEN);

	printf("当前屏幕总的分辨率为:%d×%d \n", aScreenWidth, aScreenHeight);

	getchar();

	return 0;
}

猜你喜欢

转载自blog.csdn.net/hellokandy/article/details/81013774