わびさびサンプルソース

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

デスクトップの幅と高さを取得する

デスクトップの幅と高さを取得するには、GetSystemMetrics関数を利用します。 SM_CXSCREENを渡すと幅、SM_CYSCREENを渡すと高さを取得する事ができます。

#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_CXSCREEN );

	// デスクトップの高さを取得
	int nDesktopHeight = ::GetSystemMetrics( SM_CYSCREEN );

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

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

実行結果

幅   = 1920
高さ = 1080






わびさびサンプルソース

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