わびさびサンプルソース

WindowsやHTML5などのプログラムのサンプルコードやフリーソフトを提供します。

デスクトップのフルスクリーン時の幅と高さを取得する

デスクトップのフルスクリーン時の幅と高さを取得するには、GetSystemMetrics関数を利用します。 SM_CXFULLSCREENを渡すと幅、SM_CYFULLSCREENを渡すと高さを取得する事ができます。

#include <stdio.h>
#include <tchar.h>
#include <locale.h>
#include <string>
#include <iostream>
#include <windows.h>



int _tmain
(
	  int argc
	, _TCHAR* argv[]
)
{
	// 標準出力にユニコード出力する
	setlocale( LC_ALL, "Japanese" );

	// デスクトップのフルスクリーン時の幅を取得
	int nDesktopWidth  = ::GetSystemMetrics( SM_CXFULLSCREEN );

	// デスクトップのフルスクリーン時の高さを取得
	int nDesktopHeight = ::GetSystemMetrics( SM_CYFULLSCREEN );

	// 標準出力へ出力する
	std::wcout << L"幅   = " << nDesktopWidth  << std::endl;
	std::wcout << L"高さ = "<< nDesktopHeight << std::endl;

	// 正常終了
	return( 0 );
}

実行結果

幅   = 1920
高さ = 1017






わびさびサンプルソース

WindowsやHTML5などのプログラムのサンプルコードやフリーソフトを提供します。