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

ChoosePixelFormat

関数
条件に最も適合するピクセル形式を選択する。
DLLGDI32.dll呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

INT ChoosePixelFormat(
    HDC hdc,
    const PIXELFORMATDESCRIPTOR* ppfd
);

パラメーター

名前方向
hdcHDCin
ppfdPIXELFORMATDESCRIPTOR*in

戻り値の型: INT

各言語での呼び出し定義

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

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

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

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

var (
	gdi32 = windows.NewLazySystemDLL("GDI32.dll")
	procChoosePixelFormat = gdi32.NewProc("ChoosePixelFormat")
)

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