Win32 API 日本語リファレンス
ホームGraphics.OpenGL › DescribePixelFormat

DescribePixelFormat

関数
指定したピクセル形式の詳細情報を取得する。
DLLGDI32.dll呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

// GDI32.dll
#include <windows.h>

INT DescribePixelFormat(
    HDC hdc,
    INT iPixelFormat,
    DWORD nBytes,
    PIXELFORMATDESCRIPTOR* ppfd   // optional
);

パラメーター

名前方向
hdcHDCin
iPixelFormatINTin
nBytesDWORDin
ppfdPIXELFORMATDESCRIPTOR*outoptional

戻り値の型: INT

各言語での呼び出し定義

// GDI32.dll
#include <windows.h>

INT DescribePixelFormat(
    HDC hdc,
    INT iPixelFormat,
    DWORD nBytes,
    PIXELFORMATDESCRIPTOR* ppfd   // optional
);
[DllImport("GDI32.dll", SetLastError = true, ExactSpelling = true)]
static extern int DescribePixelFormat(
    IntPtr hdc,   // HDC
    int iPixelFormat,   // INT
    uint nBytes,   // DWORD
    IntPtr ppfd   // PIXELFORMATDESCRIPTOR* optional, out
);
<DllImport("GDI32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function DescribePixelFormat(
    hdc As IntPtr,   ' HDC
    iPixelFormat As Integer,   ' INT
    nBytes As UInteger,   ' DWORD
    ppfd As IntPtr   ' PIXELFORMATDESCRIPTOR* optional, out
) As Integer
End Function
' hdc : HDC
' iPixelFormat : INT
' nBytes : DWORD
' ppfd : PIXELFORMATDESCRIPTOR* optional, out
Declare PtrSafe Function DescribePixelFormat Lib "gdi32" ( _
    ByVal hdc As LongPtr, _
    ByVal iPixelFormat As Long, _
    ByVal nBytes As Long, _
    ByVal ppfd As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

DescribePixelFormat = ctypes.windll.gdi32.DescribePixelFormat
DescribePixelFormat.restype = ctypes.c_int
DescribePixelFormat.argtypes = [
    wintypes.HANDLE,  # hdc : HDC
    ctypes.c_int,  # iPixelFormat : INT
    wintypes.DWORD,  # nBytes : DWORD
    ctypes.c_void_p,  # ppfd : PIXELFORMATDESCRIPTOR* optional, out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('GDI32.dll')
DescribePixelFormat = Fiddle::Function.new(
  lib['DescribePixelFormat'],
  [
    Fiddle::TYPE_VOIDP,  # hdc : HDC
    Fiddle::TYPE_INT,  # iPixelFormat : INT
    -Fiddle::TYPE_INT,  # nBytes : DWORD
    Fiddle::TYPE_VOIDP,  # ppfd : PIXELFORMATDESCRIPTOR* optional, out
  ],
  Fiddle::TYPE_INT)
#[link(name = "gdi32")]
extern "system" {
    fn DescribePixelFormat(
        hdc: *mut core::ffi::c_void,  // HDC
        iPixelFormat: i32,  // INT
        nBytes: u32,  // DWORD
        ppfd: *mut PIXELFORMATDESCRIPTOR  // PIXELFORMATDESCRIPTOR* optional, out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("GDI32.dll", SetLastError = true)]
public static extern int DescribePixelFormat(IntPtr hdc, int iPixelFormat, uint nBytes, IntPtr ppfd);
"@
$api = Add-Type -MemberDefinition $sig -Name 'GDI32_DescribePixelFormat' -Namespace Win32 -PassThru
# $api::DescribePixelFormat(hdc, iPixelFormat, nBytes, ppfd)
#uselib "GDI32.dll"
#func global DescribePixelFormat "DescribePixelFormat" sptr, sptr, sptr, sptr
; DescribePixelFormat hdc, iPixelFormat, nBytes, varptr(ppfd)   ; 戻り値は stat
; hdc : HDC -> "sptr"
; iPixelFormat : INT -> "sptr"
; nBytes : DWORD -> "sptr"
; ppfd : PIXELFORMATDESCRIPTOR* optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "GDI32.dll"
#cfunc global DescribePixelFormat "DescribePixelFormat" sptr, int, int, var
; res = DescribePixelFormat(hdc, iPixelFormat, nBytes, ppfd)
; hdc : HDC -> "sptr"
; iPixelFormat : INT -> "int"
; nBytes : DWORD -> "int"
; ppfd : PIXELFORMATDESCRIPTOR* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; INT DescribePixelFormat(HDC hdc, INT iPixelFormat, DWORD nBytes, PIXELFORMATDESCRIPTOR* ppfd)
#uselib "GDI32.dll"
#cfunc global DescribePixelFormat "DescribePixelFormat" intptr, int, int, var
; res = DescribePixelFormat(hdc, iPixelFormat, nBytes, ppfd)
; hdc : HDC -> "intptr"
; iPixelFormat : INT -> "int"
; nBytes : DWORD -> "int"
; ppfd : PIXELFORMATDESCRIPTOR* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	gdi32 = windows.NewLazySystemDLL("GDI32.dll")
	procDescribePixelFormat = gdi32.NewProc("DescribePixelFormat")
)

// hdc (HDC), iPixelFormat (INT), nBytes (DWORD), ppfd (PIXELFORMATDESCRIPTOR* optional, out)
r1, _, err := procDescribePixelFormat.Call(
	uintptr(hdc),
	uintptr(iPixelFormat),
	uintptr(nBytes),
	uintptr(ppfd),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INT
function DescribePixelFormat(
  hdc: THandle;   // HDC
  iPixelFormat: Integer;   // INT
  nBytes: DWORD;   // DWORD
  ppfd: Pointer   // PIXELFORMATDESCRIPTOR* optional, out
): Integer; stdcall;
  external 'GDI32.dll' name 'DescribePixelFormat';
result := DllCall("GDI32\DescribePixelFormat"
    , "Ptr", hdc   ; HDC
    , "Int", iPixelFormat   ; INT
    , "UInt", nBytes   ; DWORD
    , "Ptr", ppfd   ; PIXELFORMATDESCRIPTOR* optional, out
    , "Int")   ; return: INT
●DescribePixelFormat(hdc, iPixelFormat, nBytes, ppfd) = DLL("GDI32.dll", "int DescribePixelFormat(void*, int, dword, void*)")
# 呼び出し: DescribePixelFormat(hdc, iPixelFormat, nBytes, ppfd)
# hdc : HDC -> "void*"
# iPixelFormat : INT -> "int"
# nBytes : DWORD -> "dword"
# ppfd : PIXELFORMATDESCRIPTOR* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。