ホーム › Graphics.OpenGL › ChoosePixelFormat
ChoosePixelFormat
関数条件に最も適合するピクセル形式を選択する。
シグネチャ
// GDI32.dll
#include <windows.h>
INT ChoosePixelFormat(
HDC hdc,
const PIXELFORMATDESCRIPTOR* ppfd
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hdc | HDC | in | ピクセル形式を選択する対象のデバイスコンテキストハンドル(HDC)。 |
| ppfd | PIXELFORMATDESCRIPTOR* | in | 希望するピクセル形式の属性を示すPIXELFORMATDESCRIPTOR構造体へのポインタ。 |
戻り値の型: 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 方式にも切替可。#uselib "GDI32.dll" #cfunc global ChoosePixelFormat "ChoosePixelFormat" sptr, sptr ; res = ChoosePixelFormat(hdc, varptr(ppfd)) ; hdc : HDC -> "sptr" ; ppfd : PIXELFORMATDESCRIPTOR* -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは 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 方式にも切替可。; INT ChoosePixelFormat(HDC hdc, PIXELFORMATDESCRIPTOR* ppfd) #uselib "GDI32.dll" #cfunc global ChoosePixelFormat "ChoosePixelFormat" intptr, intptr ; res = ChoosePixelFormat(hdc, varptr(ppfd)) ; hdc : HDC -> "intptr" ; ppfd : PIXELFORMATDESCRIPTOR* -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは 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 // INTfunction 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)。const std = @import("std");
extern "gdi32" fn ChoosePixelFormat(
hdc: ?*anyopaque, // HDC
ppfd: [*c]PIXELFORMATDESCRIPTOR // PIXELFORMATDESCRIPTOR*
) callconv(std.os.windows.WINAPI) i32;proc ChoosePixelFormat(
hdc: pointer, # HDC
ppfd: ptr PIXELFORMATDESCRIPTOR # PIXELFORMATDESCRIPTOR*
): int32 {.importc: "ChoosePixelFormat", stdcall, dynlib: "GDI32.dll".}pragma(lib, "gdi32");
extern(Windows)
int ChoosePixelFormat(
void* hdc, // HDC
PIXELFORMATDESCRIPTOR* ppfd // PIXELFORMATDESCRIPTOR*
);ccall((:ChoosePixelFormat, "GDI32.dll"), stdcall, Int32,
(Ptr{Cvoid}, Ptr{PIXELFORMATDESCRIPTOR}),
hdc, ppfd)
# hdc : HDC -> Ptr{Cvoid}
# ppfd : PIXELFORMATDESCRIPTOR* -> Ptr{PIXELFORMATDESCRIPTOR}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t ChoosePixelFormat(
void* hdc,
void* ppfd);
]]
local gdi32 = ffi.load("gdi32")
-- gdi32.ChoosePixelFormat(hdc, ppfd)
-- hdc : HDC
-- ppfd : PIXELFORMATDESCRIPTOR*
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('GDI32.dll');
const ChoosePixelFormat = lib.func('__stdcall', 'ChoosePixelFormat', 'int32_t', ['void *', 'void *']);
// ChoosePixelFormat(hdc, ppfd)
// hdc : HDC -> 'void *'
// ppfd : PIXELFORMATDESCRIPTOR* -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("GDI32.dll", {
ChoosePixelFormat: { parameters: ["pointer", "pointer"], result: "i32" },
});
// lib.symbols.ChoosePixelFormat(hdc, ppfd)
// hdc : HDC -> "pointer"
// ppfd : PIXELFORMATDESCRIPTOR* -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t ChoosePixelFormat(
void* hdc,
void* ppfd);
C, "GDI32.dll");
// $ffi->ChoosePixelFormat(hdc, ppfd);
// hdc : HDC
// ppfd : PIXELFORMATDESCRIPTOR*
// 構造体/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 ChoosePixelFormat(
Pointer hdc, // HDC
Pointer ppfd // PIXELFORMATDESCRIPTOR*
);
}@[Link("gdi32")]
lib LibGDI32
fun ChoosePixelFormat = ChoosePixelFormat(
hdc : Void*, # HDC
ppfd : PIXELFORMATDESCRIPTOR* # PIXELFORMATDESCRIPTOR*
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef ChoosePixelFormatNative = Int32 Function(Pointer<Void>, Pointer<Void>);
typedef ChoosePixelFormatDart = int Function(Pointer<Void>, Pointer<Void>);
final ChoosePixelFormat = DynamicLibrary.open('GDI32.dll')
.lookupFunction<ChoosePixelFormatNative, ChoosePixelFormatDart>('ChoosePixelFormat');
// hdc : HDC -> Pointer<Void>
// ppfd : PIXELFORMATDESCRIPTOR* -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function ChoosePixelFormat(
hdc: THandle; // HDC
ppfd: Pointer // PIXELFORMATDESCRIPTOR*
): Integer; stdcall;
external 'GDI32.dll' name 'ChoosePixelFormat';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "ChoosePixelFormat"
c_ChoosePixelFormat :: Ptr () -> Ptr () -> IO Int32
-- hdc : HDC -> Ptr ()
-- ppfd : PIXELFORMATDESCRIPTOR* -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let choosepixelformat =
foreign "ChoosePixelFormat"
((ptr void) @-> (ptr void) @-> returning int32_t)
(* hdc : HDC -> (ptr void) *)
(* ppfd : PIXELFORMATDESCRIPTOR* -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library gdi32 (t "GDI32.dll"))
(cffi:use-foreign-library gdi32)
(cffi:defcfun ("ChoosePixelFormat" choose-pixel-format :convention :stdcall) :int32
(hdc :pointer) ; HDC
(ppfd :pointer)) ; PIXELFORMATDESCRIPTOR*
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $ChoosePixelFormat = Win32::API::More->new('GDI32',
'int ChoosePixelFormat(HANDLE hdc, LPVOID ppfd)');
# my $ret = $ChoosePixelFormat->Call($hdc, $ppfd);
# hdc : HDC -> HANDLE
# ppfd : PIXELFORMATDESCRIPTOR* -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。