ホーム › Graphics.Gdi › Chord
Chord
関数楕円と直線で囲まれた弦(コード)図形を描画する。
シグネチャ
// GDI32.dll
#include <windows.h>
BOOL Chord(
HDC hdc,
INT x1,
INT y1,
INT x2,
INT y2,
INT x3,
INT y3,
INT x4,
INT y4
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hdc | HDC | in | 弦を描画するデバイスコンテキストへのハンドルです。 |
| x1 | INT | in | 境界矩形の左上隅の x 座標(論理座標)です。 |
| y1 | INT | in | 境界矩形の左上隅の y 座標(論理座標)です。 |
| x2 | INT | in | 境界矩形の右下隅の x 座標(論理座標)です。 |
| y2 | INT | in | 境界矩形の右下隅の y 座標(論理座標)です。 |
| x3 | INT | in | 弦の開始を定義する半径の端点の x 座標(論理座標)です。 |
| y3 | INT | in | 弦の開始を定義する半径の端点の y 座標(論理座標)です。 |
| x4 | INT | in | 弦の終了を定義する半径の端点の x 座標(論理座標)です。 |
| y4 | INT | in | 弦の終了を定義する半径の端点の y 座標(論理座標)です。 |
戻り値の型: BOOL
公式ドキュメント
Chord 関数は弦(楕円と線分(割線と呼ばれる)の交差によって囲まれた領域)を描画します。弦は現在のペンで輪郭が描かれ、現在のブラシで塗りつぶされます。
戻り値
関数が成功した場合、戻り値は 0 以外の値です。
関数が失敗した場合、戻り値は 0 です。
解説(Remarks)
弦の曲線は、指定された境界矩形に収まる楕円によって定義されます。曲線は楕円が最初の半径と交差する点から始まり、楕円が 2 番目の半径と交差する点まで反時計回りに延びます。弦は、最初の半径と曲線の交点から 2 番目の半径と曲線の交点まで線を引くことによって閉じられます。
曲線の開始点と終了点が同じ場合は、完全な楕円が描画されます。
現在位置は Chord によって使用も更新もされません。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// GDI32.dll
#include <windows.h>
BOOL Chord(
HDC hdc,
INT x1,
INT y1,
INT x2,
INT y2,
INT x3,
INT y3,
INT x4,
INT y4
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("GDI32.dll", ExactSpelling = true)]
static extern bool Chord(
IntPtr hdc, // HDC
int x1, // INT
int y1, // INT
int x2, // INT
int y2, // INT
int x3, // INT
int y3, // INT
int x4, // INT
int y4 // INT
);<DllImport("GDI32.dll", ExactSpelling:=True)>
Public Shared Function Chord(
hdc As IntPtr, ' HDC
x1 As Integer, ' INT
y1 As Integer, ' INT
x2 As Integer, ' INT
y2 As Integer, ' INT
x3 As Integer, ' INT
y3 As Integer, ' INT
x4 As Integer, ' INT
y4 As Integer ' INT
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' hdc : HDC
' x1 : INT
' y1 : INT
' x2 : INT
' y2 : INT
' x3 : INT
' y3 : INT
' x4 : INT
' y4 : INT
Declare PtrSafe Function Chord Lib "gdi32" ( _
ByVal hdc As LongPtr, _
ByVal x1 As Long, _
ByVal y1 As Long, _
ByVal x2 As Long, _
ByVal y2 As Long, _
ByVal x3 As Long, _
ByVal y3 As Long, _
ByVal x4 As Long, _
ByVal y4 As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
Chord = ctypes.windll.gdi32.Chord
Chord.restype = wintypes.BOOL
Chord.argtypes = [
wintypes.HANDLE, # hdc : HDC
ctypes.c_int, # x1 : INT
ctypes.c_int, # y1 : INT
ctypes.c_int, # x2 : INT
ctypes.c_int, # y2 : INT
ctypes.c_int, # x3 : INT
ctypes.c_int, # y3 : INT
ctypes.c_int, # x4 : INT
ctypes.c_int, # y4 : INT
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('GDI32.dll')
Chord = Fiddle::Function.new(
lib['Chord'],
[
Fiddle::TYPE_VOIDP, # hdc : HDC
Fiddle::TYPE_INT, # x1 : INT
Fiddle::TYPE_INT, # y1 : INT
Fiddle::TYPE_INT, # x2 : INT
Fiddle::TYPE_INT, # y2 : INT
Fiddle::TYPE_INT, # x3 : INT
Fiddle::TYPE_INT, # y3 : INT
Fiddle::TYPE_INT, # x4 : INT
Fiddle::TYPE_INT, # y4 : INT
],
Fiddle::TYPE_INT)#[link(name = "gdi32")]
extern "system" {
fn Chord(
hdc: *mut core::ffi::c_void, // HDC
x1: i32, // INT
y1: i32, // INT
x2: i32, // INT
y2: i32, // INT
x3: i32, // INT
y3: i32, // INT
x4: i32, // INT
y4: i32 // INT
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("GDI32.dll")]
public static extern bool Chord(IntPtr hdc, int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4);
"@
$api = Add-Type -MemberDefinition $sig -Name 'GDI32_Chord' -Namespace Win32 -PassThru
# $api::Chord(hdc, x1, y1, x2, y2, x3, y3, x4, y4)#uselib "GDI32.dll"
#func global Chord "Chord" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; Chord hdc, x1, y1, x2, y2, x3, y3, x4, y4 ; 戻り値は stat
; hdc : HDC -> "sptr"
; x1 : INT -> "sptr"
; y1 : INT -> "sptr"
; x2 : INT -> "sptr"
; y2 : INT -> "sptr"
; x3 : INT -> "sptr"
; y3 : INT -> "sptr"
; x4 : INT -> "sptr"
; y4 : INT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "GDI32.dll"
#cfunc global Chord "Chord" sptr, int, int, int, int, int, int, int, int
; res = Chord(hdc, x1, y1, x2, y2, x3, y3, x4, y4)
; hdc : HDC -> "sptr"
; x1 : INT -> "int"
; y1 : INT -> "int"
; x2 : INT -> "int"
; y2 : INT -> "int"
; x3 : INT -> "int"
; y3 : INT -> "int"
; x4 : INT -> "int"
; y4 : INT -> "int"; BOOL Chord(HDC hdc, INT x1, INT y1, INT x2, INT y2, INT x3, INT y3, INT x4, INT y4)
#uselib "GDI32.dll"
#cfunc global Chord "Chord" intptr, int, int, int, int, int, int, int, int
; res = Chord(hdc, x1, y1, x2, y2, x3, y3, x4, y4)
; hdc : HDC -> "intptr"
; x1 : INT -> "int"
; y1 : INT -> "int"
; x2 : INT -> "int"
; y2 : INT -> "int"
; x3 : INT -> "int"
; y3 : INT -> "int"
; x4 : INT -> "int"
; y4 : INT -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
gdi32 = windows.NewLazySystemDLL("GDI32.dll")
procChord = gdi32.NewProc("Chord")
)
// hdc (HDC), x1 (INT), y1 (INT), x2 (INT), y2 (INT), x3 (INT), y3 (INT), x4 (INT), y4 (INT)
r1, _, err := procChord.Call(
uintptr(hdc),
uintptr(x1),
uintptr(y1),
uintptr(x2),
uintptr(y2),
uintptr(x3),
uintptr(y3),
uintptr(x4),
uintptr(y4),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction Chord(
hdc: THandle; // HDC
x1: Integer; // INT
y1: Integer; // INT
x2: Integer; // INT
y2: Integer; // INT
x3: Integer; // INT
y3: Integer; // INT
x4: Integer; // INT
y4: Integer // INT
): BOOL; stdcall;
external 'GDI32.dll' name 'Chord';result := DllCall("GDI32\Chord"
, "Ptr", hdc ; HDC
, "Int", x1 ; INT
, "Int", y1 ; INT
, "Int", x2 ; INT
, "Int", y2 ; INT
, "Int", x3 ; INT
, "Int", y3 ; INT
, "Int", x4 ; INT
, "Int", y4 ; INT
, "Int") ; return: BOOL●Chord(hdc, x1, y1, x2, y2, x3, y3, x4, y4) = DLL("GDI32.dll", "bool Chord(void*, int, int, int, int, int, int, int, int)")
# 呼び出し: Chord(hdc, x1, y1, x2, y2, x3, y3, x4, y4)
# hdc : HDC -> "void*"
# x1 : INT -> "int"
# y1 : INT -> "int"
# x2 : INT -> "int"
# y2 : INT -> "int"
# x3 : INT -> "int"
# y3 : INT -> "int"
# x4 : INT -> "int"
# y4 : INT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "gdi32" fn Chord(
hdc: ?*anyopaque, // HDC
x1: i32, // INT
y1: i32, // INT
x2: i32, // INT
y2: i32, // INT
x3: i32, // INT
y3: i32, // INT
x4: i32, // INT
y4: i32 // INT
) callconv(std.os.windows.WINAPI) i32;proc Chord(
hdc: pointer, # HDC
x1: int32, # INT
y1: int32, # INT
x2: int32, # INT
y2: int32, # INT
x3: int32, # INT
y3: int32, # INT
x4: int32, # INT
y4: int32 # INT
): int32 {.importc: "Chord", stdcall, dynlib: "GDI32.dll".}pragma(lib, "gdi32");
extern(Windows)
int Chord(
void* hdc, // HDC
int x1, // INT
int y1, // INT
int x2, // INT
int y2, // INT
int x3, // INT
int y3, // INT
int x4, // INT
int y4 // INT
);ccall((:Chord, "GDI32.dll"), stdcall, Int32,
(Ptr{Cvoid}, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32),
hdc, x1, y1, x2, y2, x3, y3, x4, y4)
# hdc : HDC -> Ptr{Cvoid}
# x1 : INT -> Int32
# y1 : INT -> Int32
# x2 : INT -> Int32
# y2 : INT -> Int32
# x3 : INT -> Int32
# y3 : INT -> Int32
# x4 : INT -> Int32
# y4 : INT -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t Chord(
void* hdc,
int32_t x1,
int32_t y1,
int32_t x2,
int32_t y2,
int32_t x3,
int32_t y3,
int32_t x4,
int32_t y4);
]]
local gdi32 = ffi.load("gdi32")
-- gdi32.Chord(hdc, x1, y1, x2, y2, x3, y3, x4, y4)
-- hdc : HDC
-- x1 : INT
-- y1 : INT
-- x2 : INT
-- y2 : INT
-- x3 : INT
-- y3 : INT
-- x4 : INT
-- y4 : INT
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('GDI32.dll');
const Chord = lib.func('__stdcall', 'Chord', 'int32_t', ['void *', 'int32_t', 'int32_t', 'int32_t', 'int32_t', 'int32_t', 'int32_t', 'int32_t', 'int32_t']);
// Chord(hdc, x1, y1, x2, y2, x3, y3, x4, y4)
// hdc : HDC -> 'void *'
// x1 : INT -> 'int32_t'
// y1 : INT -> 'int32_t'
// x2 : INT -> 'int32_t'
// y2 : INT -> 'int32_t'
// x3 : INT -> 'int32_t'
// y3 : INT -> 'int32_t'
// x4 : INT -> 'int32_t'
// y4 : INT -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("GDI32.dll", {
Chord: { parameters: ["pointer", "i32", "i32", "i32", "i32", "i32", "i32", "i32", "i32"], result: "i32" },
});
// lib.symbols.Chord(hdc, x1, y1, x2, y2, x3, y3, x4, y4)
// hdc : HDC -> "pointer"
// x1 : INT -> "i32"
// y1 : INT -> "i32"
// x2 : INT -> "i32"
// y2 : INT -> "i32"
// x3 : INT -> "i32"
// y3 : INT -> "i32"
// x4 : INT -> "i32"
// y4 : INT -> "i32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t Chord(
void* hdc,
int32_t x1,
int32_t y1,
int32_t x2,
int32_t y2,
int32_t x3,
int32_t y3,
int32_t x4,
int32_t y4);
C, "GDI32.dll");
// $ffi->Chord(hdc, x1, y1, x2, y2, x3, y3, x4, y4);
// hdc : HDC
// x1 : INT
// y1 : INT
// x2 : INT
// y2 : INT
// x3 : INT
// y3 : INT
// x4 : INT
// y4 : 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);
boolean Chord(
Pointer hdc, // HDC
int x1, // INT
int y1, // INT
int x2, // INT
int y2, // INT
int x3, // INT
int y3, // INT
int x4, // INT
int y4 // INT
);
}@[Link("gdi32")]
lib LibGDI32
fun Chord = Chord(
hdc : Void*, # HDC
x1 : Int32, # INT
y1 : Int32, # INT
x2 : Int32, # INT
y2 : Int32, # INT
x3 : Int32, # INT
y3 : Int32, # INT
x4 : Int32, # INT
y4 : 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 ChordNative = Int32 Function(Pointer<Void>, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32);
typedef ChordDart = int Function(Pointer<Void>, int, int, int, int, int, int, int, int);
final Chord = DynamicLibrary.open('GDI32.dll')
.lookupFunction<ChordNative, ChordDart>('Chord');
// hdc : HDC -> Pointer<Void>
// x1 : INT -> Int32
// y1 : INT -> Int32
// x2 : INT -> Int32
// y2 : INT -> Int32
// x3 : INT -> Int32
// y3 : INT -> Int32
// x4 : INT -> Int32
// y4 : INT -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function Chord(
hdc: THandle; // HDC
x1: Integer; // INT
y1: Integer; // INT
x2: Integer; // INT
y2: Integer; // INT
x3: Integer; // INT
y3: Integer; // INT
x4: Integer; // INT
y4: Integer // INT
): BOOL; stdcall;
external 'GDI32.dll' name 'Chord';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "Chord"
c_Chord :: Ptr () -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> IO CInt
-- hdc : HDC -> Ptr ()
-- x1 : INT -> Int32
-- y1 : INT -> Int32
-- x2 : INT -> Int32
-- y2 : INT -> Int32
-- x3 : INT -> Int32
-- y3 : INT -> Int32
-- x4 : INT -> Int32
-- y4 : INT -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let chord =
foreign "Chord"
((ptr void) @-> int32_t @-> int32_t @-> int32_t @-> int32_t @-> int32_t @-> int32_t @-> int32_t @-> int32_t @-> returning int32_t)
(* hdc : HDC -> (ptr void) *)
(* x1 : INT -> int32_t *)
(* y1 : INT -> int32_t *)
(* x2 : INT -> int32_t *)
(* y2 : INT -> int32_t *)
(* x3 : INT -> int32_t *)
(* y3 : INT -> int32_t *)
(* x4 : INT -> int32_t *)
(* y4 : 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 ("Chord" chord :convention :stdcall) :int32
(hdc :pointer) ; HDC
(x1 :int32) ; INT
(y1 :int32) ; INT
(x2 :int32) ; INT
(y2 :int32) ; INT
(x3 :int32) ; INT
(y3 :int32) ; INT
(x4 :int32) ; INT
(y4 :int32)) ; INT
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $Chord = Win32::API::More->new('GDI32',
'BOOL Chord(HANDLE hdc, int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4)');
# my $ret = $Chord->Call($hdc, $x1, $y1, $x2, $y2, $x3, $y3, $x4, $y4);
# hdc : HDC -> HANDLE
# x1 : INT -> int
# y1 : INT -> int
# x2 : INT -> int
# y2 : INT -> int
# x3 : INT -> int
# y3 : INT -> int
# x4 : INT -> int
# y4 : INT -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
公式の関連項目
- f AngleArc — 中心と半径、開始角と掃引角で指定した円弧を描画する。
- f Arc — 指定した矩形と境界点に沿って楕円弧を描画する。
- f ArcTo — 現在位置から円弧を描画し現在位置を更新する。
- f Pie — 楕円の一部からなる扇形(パイ)を描画する。