UWSCでWindows8につながったモニターの物理サイズを取得する
Windows8からGetDeviceCapsがちゃんとした値を返すらしいので、作成してみた。
そのうち何かで実験する。
スクリプト
OPTION EXPLICIT IFB GET_UWSC_NAME = "DisplayInfo.uws" THEN DIM i FOR i = 0 TO MONITOR() - 1 PRINT i + " (" + MONITOR(i, MON_X) + "," + MONITOR(i, MON_Y) + ") (" + MONITOR(i, MON_WIDTH) + "," + MONITOR(i, MON_HEIGHT) + ") (" + DisplayInfo.Get(i, MON_WIDTH) + "," + DisplayInfo.Get(i, MON_HEIGHT) + ") " + DisplayInfo.Get(i) NEXT ENDIF MODULE DisplayInfo HASHTBL _width, _height FUNCTION Get(no, type=-1) RESULT = -1 IF !_width[no, HASH_EXISTS] THEN GetInfo(no) IFB _height[no, HASH_EXISTS] THEN SELECT type CASE MON_WIDTH RESULT = _width[no] CASE MON_HEIGHT RESULT = _height[no] DEFAULT RESULT = SQRT(POWER(_width[no], 2) + POWER(_height[no], 2)) / 25.4 SELEND ENDIF FEND FUNCTION GetInfo(no) RESULT = FALSE DIM device = CHR(840) + FORMAT(CHR(0), 419) IFB EnumDisplayDevicesW(NULL, no, device, 0) THEN DIM ds = SPLIT(device, CHR(0), TRUE), hdc = CreateDCW(ds[1], ds[1], NULL, NULL) IFB LENGTH(ds) > 4 THEN IFB ASC(ds[3]) AND 1 THEN _width[no] = GetDeviceCaps(hdc, 4) _height[no] = GetDeviceCaps(hdc, 6) RESULT = TRUE ENDIF ENDIF DeleteDC(hdc) ENDIF FEND DEF_DLL EnumDisplayDevicesW(var wstring, DWORD, var pwchar, DWORD): BOOL: user32 DEF_DLL CreateDCW(wstring, wstring, wstring, wstring): DWORD: gdi32 DEF_DLL DeleteDC(DWORD): BOOL: gdi32 DEF_DLL GetDeviceCaps(DWORD, int): int: gdi32 TEXTBLOCK displayinfo_uws_memo /* Device Parameters for GetDeviceCaps() */ #define DRIVERVERSION 0 /* Device driver version */ #define TECHNOLOGY 2 /* Device classification */ #define HORZSIZE 4 /* Horizontal size in millimeters */ #define VERTSIZE 6 /* Vertical size in millimeters */ #define HORZRES 8 /* Horizontal width in pixels */ #define VERTRES 10 /* Vertical height in pixels */ #define BITSPIXEL 12 /* Number of bits per pixel */ #define PLANES 14 /* Number of planes */ #define NUMBRUSHES 16 /* Number of brushes the device has */ #define NUMPENS 18 /* Number of pens the device has */ #define NUMMARKERS 20 /* Number of markers the device has */ #define NUMFONTS 22 /* Number of fonts the device has */ #define NUMCOLORS 24 /* Number of colors the device supports */ #define PDEVICESIZE 26 /* Size required for device descriptor */ #define CURVECAPS 28 /* Curve capabilities */ #define LINECAPS 30 /* Line capabilities */ #define POLYGONALCAPS 32 /* Polygonal capabilities */ #define TEXTCAPS 34 /* Text capabilities */ #define CLIPCAPS 36 /* Clipping capabilities */ #define RASTERCAPS 38 /* Bitblt capabilities */ #define ASPECTX 40 /* Length of the X leg */ #define ASPECTY 42 /* Length of the Y leg */ #define ASPECTXY 44 /* Length of the hypotenuse */ #define LOGPIXELSX 88 /* Logical pixels/inch in X */ #define LOGPIXELSY 90 /* Logical pixels/inch in Y */ #define SIZEPALETTE 104 /* Number of entries in physical palette */ #define NUMRESERVED 106 /* Number of reserved entries in palette */ #define COLORRES 108 /* Actual color resolution */ // Printing related DeviceCaps. These replace the appropriate Escapes #define PHYSICALWIDTH 110 /* Physical Width in device units */ #define PHYSICALHEIGHT 111 /* Physical Height in device units */ #define PHYSICALOFFSETX 112 /* Physical Printable Area x margin */ #define PHYSICALOFFSETY 113 /* Physical Printable Area y margin */ #define SCALINGFACTORX 114 /* Scaling factor x */ #define SCALINGFACTORY 115 /* Scaling factor y */ // Display driver specific #define VREFRESH 116 /* Current vertical refresh rate of the */ /* display device (for displays only) in Hz*/ #define DESKTOPVERTRES 117 /* Horizontal width of entire desktop in */ /* pixels */ #define DESKTOPHORZRES 118 /* Vertical height of entire desktop in */ /* pixels */ #define BLTALIGNMENT 119 /* Preferred blt alignment */ #if(WINVER >= 0x0500) #define SHADEBLENDCAPS 120 /* Shading and blending caps */ #define COLORMGMTCAPS 121 /* Color Management caps */ #endif /* WINVER >= 0x0500 */ typedef struct _DISPLAY_DEVICE { DWORD cb; TCHAR DeviceName[32]; TCHAR DeviceString[128]; DWORD StateFlags; TCHAR DeviceID[128]; TCHAR DeviceKey[128]; } DISPLAY_DEVICE, *PDISPLAY_DEVICE; ENDTEXTBLOCK ENDMODULE