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

CreateFontIndirectW

関数
LOGFONT構造体の指定に基づいて論理フォントを作成する。
DLLGDI32.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

// GDI32.dll  (Unicode / -W)
#include <windows.h>

HFONT CreateFontIndirectW(
    const LOGFONTW* lplf
);

パラメーター

名前方向
lplfLOGFONTW*in

戻り値の型: HFONT

各言語での呼び出し定義

// GDI32.dll  (Unicode / -W)
#include <windows.h>

HFONT CreateFontIndirectW(
    const LOGFONTW* lplf
);
[DllImport("GDI32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern IntPtr CreateFontIndirectW(
    IntPtr lplf   // LOGFONTW*
);
<DllImport("GDI32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function CreateFontIndirectW(
    lplf As IntPtr   ' LOGFONTW*
) As IntPtr
End Function
' lplf : LOGFONTW*
Declare PtrSafe Function CreateFontIndirectW Lib "gdi32" ( _
    ByVal lplf As LongPtr) As LongPtr
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

CreateFontIndirectW = ctypes.windll.gdi32.CreateFontIndirectW
CreateFontIndirectW.restype = ctypes.c_void_p
CreateFontIndirectW.argtypes = [
    ctypes.c_void_p,  # lplf : LOGFONTW*
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('GDI32.dll')
CreateFontIndirectW = Fiddle::Function.new(
  lib['CreateFontIndirectW'],
  [
    Fiddle::TYPE_VOIDP,  # lplf : LOGFONTW*
  ],
  Fiddle::TYPE_VOIDP)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "gdi32")]
extern "system" {
    fn CreateFontIndirectW(
        lplf: *const LOGFONTW  // LOGFONTW*
    ) -> *mut core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("GDI32.dll", CharSet = CharSet.Unicode)]
public static extern IntPtr CreateFontIndirectW(IntPtr lplf);
"@
$api = Add-Type -MemberDefinition $sig -Name 'GDI32_CreateFontIndirectW' -Namespace Win32 -PassThru
# $api::CreateFontIndirectW(lplf)
#uselib "GDI32.dll"
#func global CreateFontIndirectW "CreateFontIndirectW" wptr
; CreateFontIndirectW varptr(lplf)   ; 戻り値は stat
; lplf : LOGFONTW* -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "GDI32.dll"
#cfunc global CreateFontIndirectW "CreateFontIndirectW" var
; res = CreateFontIndirectW(lplf)
; lplf : LOGFONTW* -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HFONT CreateFontIndirectW(LOGFONTW* lplf)
#uselib "GDI32.dll"
#cfunc global CreateFontIndirectW "CreateFontIndirectW" var
; res = CreateFontIndirectW(lplf)
; lplf : LOGFONTW* -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	gdi32 = windows.NewLazySystemDLL("GDI32.dll")
	procCreateFontIndirectW = gdi32.NewProc("CreateFontIndirectW")
)

// lplf (LOGFONTW*)
r1, _, err := procCreateFontIndirectW.Call(
	uintptr(lplf),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HFONT
function CreateFontIndirectW(
  lplf: Pointer   // LOGFONTW*
): THandle; stdcall;
  external 'GDI32.dll' name 'CreateFontIndirectW';
result := DllCall("GDI32\CreateFontIndirectW"
    , "Ptr", lplf   ; LOGFONTW*
    , "Ptr")   ; return: HFONT
●CreateFontIndirectW(lplf) = DLL("GDI32.dll", "void* CreateFontIndirectW(void*)")
# 呼び出し: CreateFontIndirectW(lplf)
# lplf : LOGFONTW* -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。