開発環境 |
Microsoft Visual C++ 2010 Express (SP1) |
実行環境 |
Microsoft Windows XP Home Edition (SP3) |
プロジェクトの種類 |
Win32 コンソール アプリケーション |
プロジェクト名 |
devcaps |
アプリケーションの種類 |
コンソール アプリケーション |
追加のオプション |
空のプロジェクト |
devcaps.c
#include <tchar.h>
#include <Windows.h>
#define pxtocm(px,dpi) ((px) * 2.54 / (dpi))
#define VarTrace(fmt,var) _tprintf(TEXT(#var)TEXT("=[")fmt##TEXT("]\n"), var)
void PrintDevCaps(HDC hdc)
{
int nHorzRes = GetDeviceCaps(hdc, HORZRES);
int nVertRes = GetDeviceCaps(hdc, VERTRES);
int nPhysicalWidth = GetDeviceCaps(hdc, PHYSICALWIDTH);
int nPhysicalHeight = GetDeviceCaps(hdc, PHYSICALHEIGHT);
int nPhysicalOffsetX = GetDeviceCaps(hdc, PHYSICALOFFSETX);
int nPhysicalOffsetY = GetDeviceCaps(hdc, PHYSICALOFFSETY);
int nLogPixelsX = GetDeviceCaps(hdc, LOGPIXELSX);
int nLogPixelsY = GetDeviceCaps(hdc, LOGPIXELSY);
double dWidth = pxtocm(nPhysicalWidth ? nPhysicalWidth : nHorzRes, nLogPixelsX);
double dHeight = pxtocm(nPhysicalHeight ? nPhysicalHeight : nVertRes, nLogPixelsY);
VarTrace(TEXT("%d"), nHorzRes);
VarTrace(TEXT("%d"), nVertRes);
VarTrace(TEXT("%d"), nPhysicalWidth);
VarTrace(TEXT("%d"), nPhysicalHeight);
VarTrace(TEXT("%d"), nPhysicalOffsetX);
VarTrace(TEXT("%d"), nPhysicalOffsetY);
VarTrace(TEXT("%d"), nLogPixelsX);
VarTrace(TEXT("%d"), nLogPixelsY);
VarTrace(TEXT("%.4f cm"), dWidth);
VarTrace(TEXT("%.4f cm"), dHeight);
}
int main()
{
PRINTDLG pd;
HDC hdc;
HGLOBAL hr;
BOOL br;
_tprintf(TEXT("\n[display]\n"));
hdc = CreateIC(TEXT("DISPLAY"), NULL, NULL, NULL);
if (hdc == NULL) {
return 1;
}
PrintDevCaps(hdc);
br = DeleteDC(hdc);
_tprintf(TEXT("\n[default printer]\n"));
ZeroMemory(&pd, sizeof pd);
pd.lStructSize = sizeof pd;
pd.Flags = PD_RETURNDEFAULT | PD_RETURNIC;
br = PrintDlg(&pd); // ウィンドウがないのでPrintDlgExの代用
if (br == FALSE) {
return 1;
}
if (pd.hDC == NULL) {
return 1;
}
PrintDevCaps(pd.hDC);
br = DeleteDC(pd.hDC);
hr = GlobalFree(pd.hDevMode);
hr = GlobalFree(pd.hDevNames);
return 0;
}
実行
[display]
nHorzRes=[1920]
nVertRes=[1200]
nPhysicalWidth=[0]
nPhysicalHeight=[0]
nPhysicalOffsetX=[0]
nPhysicalOffsetY=[0]
nLogPixelsX=[96]
nLogPixelsY=[96]
dWidth=[50.8000 cm]
dHeight=[31.7500 cm]
[default printer]
nHorzRes=[6826]
nVertRes=[4800]
nPhysicalWidth=[7015]
nPhysicalHeight=[4960]
nPhysicalOffsetX=[70]
nPhysicalOffsetY=[80]
nLogPixelsX=[600]
nLogPixelsY=[600]
dWidth=[29.6968 cm]
dHeight=[20.9973 cm]
最終更新:2012年10月10日 07:33