ホーム › Graphics.Gdi › GetDeviceCaps
GetDeviceCaps
関数デバイスの能力や属性情報を取得する。
シグネチャ
// GDI32.dll
#include <windows.h>
INT GetDeviceCaps(
HDC hdc, // optional
INT index
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| hdc | HDC | inoptional | DC へのハンドル。 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| index | INT | in | 返す項目。このパラメーターには、次のいずれかの値を指定できます。
|
戻り値の型: INT
公式ドキュメント
GetDeviceCaps 関数は、指定したデバイスについてデバイス固有の情報を取得します。
戻り値
戻り値は、目的の項目の値を示します。
nIndex が BITSPIXEL で、デバイスが 15bpp または 16bpp の場合、戻り値は 16 になります。
解説(Remarks)
nIndex が SHADEBLENDCAPS の場合:
- プリンターの場合、GetDeviceCaps はプリンターが報告する内容をそのまま返します。
- ディスプレイデバイスの場合、すべてのブレンディング操作が利用可能です。SB_NONE のほかに返される値は SB_CONST_ALPHA と SB_PIXEL_ALPHA のみであり、これらはこれらの操作がアクセラレートされているかどうかを示します。
注意 通常、Display1 がプライマリモニターですが、常にそうとは限りません。
| Index | 置き換えられるプリンターエスケープ |
|---|---|
| PHYSICALWIDTH | GETPHYSPAGESIZE |
| PHYSICALHEIGHT | GETPHYSPAGESIZE |
| PHYSICALOFFSETX | GETPRINTINGOFFSET |
| PHYSICALOFFSETY | GETPHYSICALOFFSET |
| SCALINGFACTORX | GETSCALINGFACTOR |
| SCALINGFACTORY | GETSCALINGFACTOR |
注意 GetDeviceCaps は、ディスプレイドライバーが提供する情報を報告します。ディスプレイドライバーが情報の報告を拒否した場合、GetDeviceCaps は固定の計算に基づいて情報を算出します。ディスプレイドライバーが無効な情報を報告した場合、GetDeviceCaps はその無効な情報を返します。また、ディスプレイドライバーが情報の報告を拒否した場合、GetDeviceCaps は固定の DPI(96 DPI)または固定のサイズ(ディスプレイドライバーが提供した情報・提供しなかった情報に応じて)のいずれかを前提とするため、誤った情報を算出する可能性があります。残念ながら、Windows ディスプレイドライバーモデル(WDDM)(Windows Vista で導入)に基づいて実装されたディスプレイドライバーでは GDI が情報を取得できなくなるため、GetDeviceCaps は常に情報を算出する必要があります。
例
例については、Preparing to Print を参照してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// GDI32.dll
#include <windows.h>
INT GetDeviceCaps(
HDC hdc, // optional
INT index
);[DllImport("GDI32.dll", ExactSpelling = true)]
static extern int GetDeviceCaps(
IntPtr hdc, // HDC optional
int index // INT
);<DllImport("GDI32.dll", ExactSpelling:=True)>
Public Shared Function GetDeviceCaps(
hdc As IntPtr, ' HDC optional
index As Integer ' INT
) As Integer
End Function' hdc : HDC optional
' index : INT
Declare PtrSafe Function GetDeviceCaps Lib "gdi32" ( _
ByVal hdc As LongPtr, _
ByVal index As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GetDeviceCaps = ctypes.windll.gdi32.GetDeviceCaps
GetDeviceCaps.restype = ctypes.c_int
GetDeviceCaps.argtypes = [
wintypes.HANDLE, # hdc : HDC optional
ctypes.c_int, # index : INT
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('GDI32.dll')
GetDeviceCaps = Fiddle::Function.new(
lib['GetDeviceCaps'],
[
Fiddle::TYPE_VOIDP, # hdc : HDC optional
Fiddle::TYPE_INT, # index : INT
],
Fiddle::TYPE_INT)#[link(name = "gdi32")]
extern "system" {
fn GetDeviceCaps(
hdc: *mut core::ffi::c_void, // HDC optional
index: i32 // INT
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("GDI32.dll")]
public static extern int GetDeviceCaps(IntPtr hdc, int index);
"@
$api = Add-Type -MemberDefinition $sig -Name 'GDI32_GetDeviceCaps' -Namespace Win32 -PassThru
# $api::GetDeviceCaps(hdc, index)#uselib "GDI32.dll"
#func global GetDeviceCaps "GetDeviceCaps" sptr, sptr
; GetDeviceCaps hdc, index ; 戻り値は stat
; hdc : HDC optional -> "sptr"
; index : INT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "GDI32.dll"
#cfunc global GetDeviceCaps "GetDeviceCaps" sptr, int
; res = GetDeviceCaps(hdc, index)
; hdc : HDC optional -> "sptr"
; index : INT -> "int"; INT GetDeviceCaps(HDC hdc, INT index)
#uselib "GDI32.dll"
#cfunc global GetDeviceCaps "GetDeviceCaps" intptr, int
; res = GetDeviceCaps(hdc, index)
; hdc : HDC optional -> "intptr"
; index : INT -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
gdi32 = windows.NewLazySystemDLL("GDI32.dll")
procGetDeviceCaps = gdi32.NewProc("GetDeviceCaps")
)
// hdc (HDC optional), index (INT)
r1, _, err := procGetDeviceCaps.Call(
uintptr(hdc),
uintptr(index),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // INTfunction GetDeviceCaps(
hdc: THandle; // HDC optional
index: Integer // INT
): Integer; stdcall;
external 'GDI32.dll' name 'GetDeviceCaps';result := DllCall("GDI32\GetDeviceCaps"
, "Ptr", hdc ; HDC optional
, "Int", index ; INT
, "Int") ; return: INT●GetDeviceCaps(hdc, index) = DLL("GDI32.dll", "int GetDeviceCaps(void*, int)")
# 呼び出し: GetDeviceCaps(hdc, index)
# hdc : HDC optional -> "void*"
# index : INT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "gdi32" fn GetDeviceCaps(
hdc: ?*anyopaque, // HDC optional
index: i32 // INT
) callconv(std.os.windows.WINAPI) i32;proc GetDeviceCaps(
hdc: pointer, # HDC optional
index: int32 # INT
): int32 {.importc: "GetDeviceCaps", stdcall, dynlib: "GDI32.dll".}pragma(lib, "gdi32");
extern(Windows)
int GetDeviceCaps(
void* hdc, // HDC optional
int index // INT
);ccall((:GetDeviceCaps, "GDI32.dll"), stdcall, Int32,
(Ptr{Cvoid}, Int32),
hdc, index)
# hdc : HDC optional -> Ptr{Cvoid}
# index : INT -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t GetDeviceCaps(
void* hdc,
int32_t index);
]]
local gdi32 = ffi.load("gdi32")
-- gdi32.GetDeviceCaps(hdc, index)
-- hdc : HDC optional
-- index : INT
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('GDI32.dll');
const GetDeviceCaps = lib.func('__stdcall', 'GetDeviceCaps', 'int32_t', ['void *', 'int32_t']);
// GetDeviceCaps(hdc, index)
// hdc : HDC optional -> 'void *'
// index : INT -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("GDI32.dll", {
GetDeviceCaps: { parameters: ["pointer", "i32"], result: "i32" },
});
// lib.symbols.GetDeviceCaps(hdc, index)
// hdc : HDC optional -> "pointer"
// index : INT -> "i32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t GetDeviceCaps(
void* hdc,
int32_t index);
C, "GDI32.dll");
// $ffi->GetDeviceCaps(hdc, index);
// hdc : HDC optional
// index : INT
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Gdi32 extends StdCallLibrary {
Gdi32 INSTANCE = Native.load("gdi32", Gdi32.class);
int GetDeviceCaps(
Pointer hdc, // HDC optional
int index // INT
);
}@[Link("gdi32")]
lib LibGDI32
fun GetDeviceCaps = GetDeviceCaps(
hdc : Void*, # HDC optional
index : Int32 # INT
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef GetDeviceCapsNative = Int32 Function(Pointer<Void>, Int32);
typedef GetDeviceCapsDart = int Function(Pointer<Void>, int);
final GetDeviceCaps = DynamicLibrary.open('GDI32.dll')
.lookupFunction<GetDeviceCapsNative, GetDeviceCapsDart>('GetDeviceCaps');
// hdc : HDC optional -> Pointer<Void>
// index : INT -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function GetDeviceCaps(
hdc: THandle; // HDC optional
index: Integer // INT
): Integer; stdcall;
external 'GDI32.dll' name 'GetDeviceCaps';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "GetDeviceCaps"
c_GetDeviceCaps :: Ptr () -> Int32 -> IO Int32
-- hdc : HDC optional -> Ptr ()
-- index : INT -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let getdevicecaps =
foreign "GetDeviceCaps"
((ptr void) @-> int32_t @-> returning int32_t)
(* hdc : HDC optional -> (ptr void) *)
(* index : INT -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library gdi32 (t "GDI32.dll"))
(cffi:use-foreign-library gdi32)
(cffi:defcfun ("GetDeviceCaps" get-device-caps :convention :stdcall) :int32
(hdc :pointer) ; HDC optional
(index :int32)) ; INT
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $GetDeviceCaps = Win32::API::More->new('GDI32',
'int GetDeviceCaps(HANDLE hdc, int index)');
# my $ret = $GetDeviceCaps->Call($hdc, $index);
# hdc : HDC optional -> HANDLE
# index : INT -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
公式の関連項目
- f CreateEnhMetaFileW — 拡張メタファイル記録用のデバイスコンテキストを作成する(Unicode版)。
- f CreateICW — 指定デバイス用の情報コンテキストを作成する。
- f DeviceCapabilitiesW — プリンタドライバの機能や対応値を問い合わせる(Unicode版)。
- f GetDIBits — ビットマップのビットをDIB形式で取得する。
- f GetObjectType — 指定したGDIオブジェクトの種類を取得する。
- f SetDIBits — DIBのビットでビットマップのピクセルを設定する。
- f SetDIBitsToDevice — DIBのピクセルを直接デバイスの矩形領域へ転送する。
- f StretchBlt — ソース矩形を伸縮しながら転送先矩形へビット転送する。
- f StretchDIBits — DIBのピクセルを伸縮して転送先矩形へ転送する。