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

SetPolyFillMode

関数
多角形の塗りつぶしモードを設定する。
DLLGDI32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

INT SetPolyFillMode(
    HDC hdc,
    CREATE_POLYGON_RGN_MODE mode
);

パラメーター

名前方向説明
hdcHDCinデバイスコンテキストへのハンドル。
modeCREATE_POLYGON_RGN_MODEin

新しい塗りつぶしモード。このパラメーターには次の値のいずれかを指定できます。

意味
ALTERNATE
alternate モードを選択します(各走査線上で、奇数番目と偶数番目のポリゴンの辺の間の領域を塗りつぶします)。
WINDING
winding モードを選択します(巻き数(winding value)が 0 でない任意の領域を塗りつぶします)。

戻り値の型: INT

公式ドキュメント

SetPolyFillMode 関数は、ポリゴンを塗りつぶす関数で使用されるポリゴンの塗りつぶしモードを設定します。

戻り値

戻り値は、以前の塗りつぶしモードを示します。エラーが発生した場合、戻り値は 0 です。

解説(Remarks)

一般に、これらのモードの違いは、複雑で重なり合うポリゴンを塗りつぶす必要がある場合にのみ現れます(例えば、中央に五角形を持つ五芒星を形成する五辺のポリゴンなど)。このような場合、ALTERNATE モードはポリゴン内の 1 つおきの閉じた領域(つまり星の各先端)を塗りつぶしますが、WINDING モードはすべての領域(つまり各先端と中央の五角形)を塗りつぶします。

塗りつぶしモードが ALTERNATE の場合、GDI は各走査線上で奇数番目と偶数番目のポリゴンの辺の間の領域を塗りつぶします。すなわち、GDI は 1 番目と 2 番目の辺の間、3 番目と 4 番目の辺の間、というように塗りつぶします。

塗りつぶしモードが WINDING の場合、GDI は巻き数(winding value)が 0 でない任意の領域を塗りつぶします。この値は、ポリゴンを描画するために使用されるペンがその領域の周りを回る回数として定義されます。ポリゴンの各辺の方向が重要となります。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

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

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

SetPolyFillMode = ctypes.windll.gdi32.SetPolyFillMode
SetPolyFillMode.restype = ctypes.c_int
SetPolyFillMode.argtypes = [
    wintypes.HANDLE,  # hdc : HDC
    ctypes.c_int,  # mode : CREATE_POLYGON_RGN_MODE
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('GDI32.dll')
SetPolyFillMode = Fiddle::Function.new(
  lib['SetPolyFillMode'],
  [
    Fiddle::TYPE_VOIDP,  # hdc : HDC
    Fiddle::TYPE_INT,  # mode : CREATE_POLYGON_RGN_MODE
  ],
  Fiddle::TYPE_INT)
#[link(name = "gdi32")]
extern "system" {
    fn SetPolyFillMode(
        hdc: *mut core::ffi::c_void,  // HDC
        mode: i32  // CREATE_POLYGON_RGN_MODE
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("GDI32.dll")]
public static extern int SetPolyFillMode(IntPtr hdc, int mode);
"@
$api = Add-Type -MemberDefinition $sig -Name 'GDI32_SetPolyFillMode' -Namespace Win32 -PassThru
# $api::SetPolyFillMode(hdc, mode)
#uselib "GDI32.dll"
#func global SetPolyFillMode "SetPolyFillMode" sptr, sptr
; SetPolyFillMode hdc, mode   ; 戻り値は stat
; hdc : HDC -> "sptr"
; mode : CREATE_POLYGON_RGN_MODE -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "GDI32.dll"
#cfunc global SetPolyFillMode "SetPolyFillMode" sptr, int
; res = SetPolyFillMode(hdc, mode)
; hdc : HDC -> "sptr"
; mode : CREATE_POLYGON_RGN_MODE -> "int"
; INT SetPolyFillMode(HDC hdc, CREATE_POLYGON_RGN_MODE mode)
#uselib "GDI32.dll"
#cfunc global SetPolyFillMode "SetPolyFillMode" intptr, int
; res = SetPolyFillMode(hdc, mode)
; hdc : HDC -> "intptr"
; mode : CREATE_POLYGON_RGN_MODE -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	gdi32 = windows.NewLazySystemDLL("GDI32.dll")
	procSetPolyFillMode = gdi32.NewProc("SetPolyFillMode")
)

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

extern "gdi32" fn SetPolyFillMode(
    hdc: ?*anyopaque, // HDC
    mode: i32 // CREATE_POLYGON_RGN_MODE
) callconv(std.os.windows.WINAPI) i32;
proc SetPolyFillMode(
    hdc: pointer,  # HDC
    mode: int32  # CREATE_POLYGON_RGN_MODE
): int32 {.importc: "SetPolyFillMode", stdcall, dynlib: "GDI32.dll".}
pragma(lib, "gdi32");
extern(Windows)
int SetPolyFillMode(
    void* hdc,   // HDC
    int mode   // CREATE_POLYGON_RGN_MODE
);
ccall((:SetPolyFillMode, "GDI32.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Int32),
      hdc, mode)
# hdc : HDC -> Ptr{Cvoid}
# mode : CREATE_POLYGON_RGN_MODE -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t SetPolyFillMode(
    void* hdc,
    int32_t mode);
]]
local gdi32 = ffi.load("gdi32")
-- gdi32.SetPolyFillMode(hdc, mode)
-- hdc : HDC
-- mode : CREATE_POLYGON_RGN_MODE
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('GDI32.dll');
const SetPolyFillMode = lib.func('__stdcall', 'SetPolyFillMode', 'int32_t', ['void *', 'int32_t']);
// SetPolyFillMode(hdc, mode)
// hdc : HDC -> 'void *'
// mode : CREATE_POLYGON_RGN_MODE -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("GDI32.dll", {
  SetPolyFillMode: { parameters: ["pointer", "i32"], result: "i32" },
});
// lib.symbols.SetPolyFillMode(hdc, mode)
// hdc : HDC -> "pointer"
// mode : CREATE_POLYGON_RGN_MODE -> "i32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t SetPolyFillMode(
    void* hdc,
    int32_t mode);
C, "GDI32.dll");
// $ffi->SetPolyFillMode(hdc, mode);
// hdc : HDC
// mode : CREATE_POLYGON_RGN_MODE
// 構造体/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 SetPolyFillMode(
        Pointer hdc,   // HDC
        int mode   // CREATE_POLYGON_RGN_MODE
    );
}
@[Link("gdi32")]
lib LibGDI32
  fun SetPolyFillMode = SetPolyFillMode(
    hdc : Void*,   # HDC
    mode : Int32   # CREATE_POLYGON_RGN_MODE
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef SetPolyFillModeNative = Int32 Function(Pointer<Void>, Int32);
typedef SetPolyFillModeDart = int Function(Pointer<Void>, int);
final SetPolyFillMode = DynamicLibrary.open('GDI32.dll')
    .lookupFunction<SetPolyFillModeNative, SetPolyFillModeDart>('SetPolyFillMode');
// hdc : HDC -> Pointer<Void>
// mode : CREATE_POLYGON_RGN_MODE -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SetPolyFillMode(
  hdc: THandle;   // HDC
  mode: Integer   // CREATE_POLYGON_RGN_MODE
): Integer; stdcall;
  external 'GDI32.dll' name 'SetPolyFillMode';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SetPolyFillMode"
  c_SetPolyFillMode :: Ptr () -> Int32 -> IO Int32
-- hdc : HDC -> Ptr ()
-- mode : CREATE_POLYGON_RGN_MODE -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let setpolyfillmode =
  foreign "SetPolyFillMode"
    ((ptr void) @-> int32_t @-> returning int32_t)
(* hdc : HDC -> (ptr void) *)
(* mode : CREATE_POLYGON_RGN_MODE -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library gdi32 (t "GDI32.dll"))
(cffi:use-foreign-library gdi32)

(cffi:defcfun ("SetPolyFillMode" set-poly-fill-mode :convention :stdcall) :int32
  (hdc :pointer)   ; HDC
  (mode :int32))   ; CREATE_POLYGON_RGN_MODE
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SetPolyFillMode = Win32::API::More->new('GDI32',
    'int SetPolyFillMode(HANDLE hdc, int mode)');
# my $ret = $SetPolyFillMode->Call($hdc, $mode);
# hdc : HDC -> HANDLE
# mode : CREATE_POLYGON_RGN_MODE -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

公式の関連項目
使用する型