ホーム › Graphics.Gdi › GetNearestColor
GetNearestColor
関数デバイスが表現可能な最も近い色を取得する。
シグネチャ
// GDI32.dll
#include <windows.h>
COLORREF GetNearestColor(
HDC hdc,
COLORREF color
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hdc | HDC | in |
| color | COLORREF | in |
戻り値の型: COLORREF
各言語での呼び出し定義
// GDI32.dll
#include <windows.h>
COLORREF GetNearestColor(
HDC hdc,
COLORREF color
);[DllImport("GDI32.dll", ExactSpelling = true)]
static extern uint GetNearestColor(
IntPtr hdc, // HDC
uint color // COLORREF
);<DllImport("GDI32.dll", ExactSpelling:=True)>
Public Shared Function GetNearestColor(
hdc As IntPtr, ' HDC
color As UInteger ' COLORREF
) As UInteger
End Function' hdc : HDC
' color : COLORREF
Declare PtrSafe Function GetNearestColor Lib "gdi32" ( _
ByVal hdc As LongPtr, _
ByVal color As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GetNearestColor = ctypes.windll.gdi32.GetNearestColor
GetNearestColor.restype = wintypes.DWORD
GetNearestColor.argtypes = [
wintypes.HANDLE, # hdc : HDC
wintypes.DWORD, # color : COLORREF
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('GDI32.dll')
GetNearestColor = Fiddle::Function.new(
lib['GetNearestColor'],
[
Fiddle::TYPE_VOIDP, # hdc : HDC
-Fiddle::TYPE_INT, # color : COLORREF
],
-Fiddle::TYPE_INT)#[link(name = "gdi32")]
extern "system" {
fn GetNearestColor(
hdc: *mut core::ffi::c_void, // HDC
color: u32 // COLORREF
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("GDI32.dll")]
public static extern uint GetNearestColor(IntPtr hdc, uint color);
"@
$api = Add-Type -MemberDefinition $sig -Name 'GDI32_GetNearestColor' -Namespace Win32 -PassThru
# $api::GetNearestColor(hdc, color)#uselib "GDI32.dll"
#func global GetNearestColor "GetNearestColor" sptr, sptr
; GetNearestColor hdc, color ; 戻り値は stat
; hdc : HDC -> "sptr"
; color : COLORREF -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "GDI32.dll"
#cfunc global GetNearestColor "GetNearestColor" sptr, int
; res = GetNearestColor(hdc, color)
; hdc : HDC -> "sptr"
; color : COLORREF -> "int"; COLORREF GetNearestColor(HDC hdc, COLORREF color)
#uselib "GDI32.dll"
#cfunc global GetNearestColor "GetNearestColor" intptr, int
; res = GetNearestColor(hdc, color)
; hdc : HDC -> "intptr"
; color : COLORREF -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
gdi32 = windows.NewLazySystemDLL("GDI32.dll")
procGetNearestColor = gdi32.NewProc("GetNearestColor")
)
// hdc (HDC), color (COLORREF)
r1, _, err := procGetNearestColor.Call(
uintptr(hdc),
uintptr(color),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // COLORREFfunction GetNearestColor(
hdc: THandle; // HDC
color: DWORD // COLORREF
): DWORD; stdcall;
external 'GDI32.dll' name 'GetNearestColor';result := DllCall("GDI32\GetNearestColor"
, "Ptr", hdc ; HDC
, "UInt", color ; COLORREF
, "UInt") ; return: COLORREF●GetNearestColor(hdc, color) = DLL("GDI32.dll", "dword GetNearestColor(void*, dword)")
# 呼び出し: GetNearestColor(hdc, color)
# hdc : HDC -> "void*"
# color : COLORREF -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。