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

GetPath

関数
DCのパスを構成する点と頂点種別を取得する。
DLLGDI32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

INT GetPath(
    HDC hdc,
    POINT* apt,   // optional
    BYTE* aj,   // optional
    INT cpt
);

パラメーター

名前方向説明
hdcHDCin閉じたパスを含むデバイスコンテキストへのハンドル。
aptPOINT*outoptional線分の端点および曲線の制御点を論理座標で受け取る POINT 構造体の配列へのポインター。
ajBYTE*outoptional

頂点の種類を受け取るバイト配列へのポインター。このパラメーターには次のいずれかの値を指定できます。

Type 説明
PT_MOVETO
lpPoints パラメーター内の対応する点が、独立した図形の開始点であることを指定します。
PT_LINETO
直前の点と lpPoints 内の対応する点が、線分の端点であることを指定します。
PT_BEZIERTO
lpPoints 内の対応する点が、ベジエ曲線の制御点または終点であることを指定します。

PT_BEZIERTO 値は常に 3 個ずつ組になって現れます。それらの直前にあるパス上の点がベジエ曲線の開始点を定義します。最初の 2 個の PT_BEZIERTO 点が制御点であり、3 個目の PT_BEZIERTO 点が終点です。

PT_LINETO または PT_BEZIERTO 値は、対応する点が図形内の最後の点であり図形を閉じる必要があることを示すために、次の値とビットごとの OR 演算子で組み合わせることができます。

Flag 説明
PT_CLOSEFIGURE
対応する線分または曲線が描画された後、図形が自動的に閉じられることを指定します。図形は、線分または曲線の端点から、最後の PT_MOVETO に対応する点へ線を引くことによって閉じられます。
cptINTinlpPoints が指す配列に格納できる POINT 構造体の総数。この値は、lpTypes が指す配列に格納できるバイト数と同じである必要があります。

戻り値の型: INT

公式ドキュメント

GetPath 関数は、指定したデバイスコンテキストに選択されているパス内の、線分の端点および曲線の制御点を定義する座標を取得します。

戻り値

nSize パラメーターが 0 以外の場合、戻り値は列挙された点の数です。nSize が 0 の場合、戻り値はパス内の点の総数であり、GetPath はバッファーに何も書き込みません。nSize が 0 以外で、かつパス内の点の数より小さい場合、戻り値は 1 です。

解説(Remarks)

hdc パラメーターで識別されるデバイスコンテキストには、閉じたパスが含まれている必要があります。

パスの点は論理座標で返されます。点はパス内にデバイス座標で格納されているため、GetPath は現在の変換の逆変換を使用して、点をデバイス座標から論理座標へ変換します。

パス内のすべての曲線を線分に変換するには、GetPath を呼び出す前に FlattenPath 関数を呼び出すことができます。

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

各言語での呼び出し定義

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

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

GetPath = ctypes.windll.gdi32.GetPath
GetPath.restype = ctypes.c_int
GetPath.argtypes = [
    wintypes.HANDLE,  # hdc : HDC
    ctypes.c_void_p,  # apt : POINT* optional, out
    ctypes.POINTER(ctypes.c_ubyte),  # aj : BYTE* optional, out
    ctypes.c_int,  # cpt : INT
]
require 'fiddle'
require 'fiddle/import'

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

var (
	gdi32 = windows.NewLazySystemDLL("GDI32.dll")
	procGetPath = gdi32.NewProc("GetPath")
)

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

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

typedef GetPathNative = Int32 Function(Pointer<Void>, Pointer<Void>, Pointer<Uint8>, Int32);
typedef GetPathDart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Uint8>, int);
final GetPath = DynamicLibrary.open('GDI32.dll')
    .lookupFunction<GetPathNative, GetPathDart>('GetPath');
// hdc : HDC -> Pointer<Void>
// apt : POINT* optional, out -> Pointer<Void>
// aj : BYTE* optional, out -> Pointer<Uint8>
// cpt : INT -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function GetPath(
  hdc: THandle;   // HDC
  apt: Pointer;   // POINT* optional, out
  aj: Pointer;   // BYTE* optional, out
  cpt: Integer   // INT
): Integer; stdcall;
  external 'GDI32.dll' name 'GetPath';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "GetPath"
  c_GetPath :: Ptr () -> Ptr () -> Ptr Word8 -> Int32 -> IO Int32
-- hdc : HDC -> Ptr ()
-- apt : POINT* optional, out -> Ptr ()
-- aj : BYTE* optional, out -> Ptr Word8
-- cpt : INT -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let getpath =
  foreign "GetPath"
    ((ptr void) @-> (ptr void) @-> (ptr uint8_t) @-> int32_t @-> returning int32_t)
(* hdc : HDC -> (ptr void) *)
(* apt : POINT* optional, out -> (ptr void) *)
(* aj : BYTE* optional, out -> (ptr uint8_t) *)
(* cpt : INT -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library gdi32 (t "GDI32.dll"))
(cffi:use-foreign-library gdi32)

(cffi:defcfun ("GetPath" get-path :convention :stdcall) :int32
  (hdc :pointer)   ; HDC
  (apt :pointer)   ; POINT* optional, out
  (aj :pointer)   ; BYTE* optional, out
  (cpt :int32))   ; INT
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $GetPath = Win32::API::More->new('GDI32',
    'int GetPath(HANDLE hdc, LPVOID apt, LPVOID aj, int cpt)');
# my $ret = $GetPath->Call($hdc, $apt, $aj, $cpt);
# hdc : HDC -> HANDLE
# apt : POINT* optional, out -> LPVOID
# aj : BYTE* optional, out -> LPVOID
# cpt : INT -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

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