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

SetPixelFormat

関数
デバイスコンテキストにピクセル形式を設定する。
DLLGDI32.dll呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

BOOL SetPixelFormat(
    HDC hdc,
    INT format,
    const PIXELFORMATDESCRIPTOR* ppfd
);

パラメーター

名前方向
hdcHDCin
formatINTin
ppfdPIXELFORMATDESCRIPTOR*in

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL SetPixelFormat(
    HDC hdc,
    INT format,
    const PIXELFORMATDESCRIPTOR* ppfd
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("GDI32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool SetPixelFormat(
    IntPtr hdc,   // HDC
    int format,   // INT
    IntPtr ppfd   // PIXELFORMATDESCRIPTOR*
);
<DllImport("GDI32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetPixelFormat(
    hdc As IntPtr,   ' HDC
    format As Integer,   ' INT
    ppfd As IntPtr   ' PIXELFORMATDESCRIPTOR*
) As Boolean
End Function
' hdc : HDC
' format : INT
' ppfd : PIXELFORMATDESCRIPTOR*
Declare PtrSafe Function SetPixelFormat Lib "gdi32" ( _
    ByVal hdc As LongPtr, _
    ByVal format 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

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

var (
	gdi32 = windows.NewLazySystemDLL("GDI32.dll")
	procSetPixelFormat = gdi32.NewProc("SetPixelFormat")
)

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