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

GetNearestPaletteIndex

関数
指定色に最も近いパレットインデックスを取得する。
DLLGDI32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

DWORD GetNearestPaletteIndex(
    HPALETTE h,
    COLORREF color
);

パラメーター

名前方向
hHPALETTEin
colorCOLORREFin

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD GetNearestPaletteIndex(
    HPALETTE h,
    COLORREF color
);
[DllImport("GDI32.dll", ExactSpelling = true)]
static extern uint GetNearestPaletteIndex(
    IntPtr h,   // HPALETTE
    uint color   // COLORREF
);
<DllImport("GDI32.dll", ExactSpelling:=True)>
Public Shared Function GetNearestPaletteIndex(
    h As IntPtr,   ' HPALETTE
    color As UInteger   ' COLORREF
) As UInteger
End Function
' h : HPALETTE
' color : COLORREF
Declare PtrSafe Function GetNearestPaletteIndex Lib "gdi32" ( _
    ByVal h 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

GetNearestPaletteIndex = ctypes.windll.gdi32.GetNearestPaletteIndex
GetNearestPaletteIndex.restype = wintypes.DWORD
GetNearestPaletteIndex.argtypes = [
    wintypes.HANDLE,  # h : HPALETTE
    wintypes.DWORD,  # color : COLORREF
]
require 'fiddle'
require 'fiddle/import'

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

var (
	gdi32 = windows.NewLazySystemDLL("GDI32.dll")
	procGetNearestPaletteIndex = gdi32.NewProc("GetNearestPaletteIndex")
)

// h (HPALETTE), color (COLORREF)
r1, _, err := procGetNearestPaletteIndex.Call(
	uintptr(h),
	uintptr(color),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function GetNearestPaletteIndex(
  h: THandle;   // HPALETTE
  color: DWORD   // COLORREF
): DWORD; stdcall;
  external 'GDI32.dll' name 'GetNearestPaletteIndex';
result := DllCall("GDI32\GetNearestPaletteIndex"
    , "Ptr", h   ; HPALETTE
    , "UInt", color   ; COLORREF
    , "UInt")   ; return: DWORD
●GetNearestPaletteIndex(h, color) = DLL("GDI32.dll", "dword GetNearestPaletteIndex(void*, dword)")
# 呼び出し: GetNearestPaletteIndex(h, color)
# h : HPALETTE -> "void*"
# color : COLORREF -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。