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

CreateFontW

関数
高さや太さなど多数の属性を指定して論理フォントを作成する。
DLLGDI32.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

HFONT CreateFontW(
    INT cHeight,
    INT cWidth,
    INT cEscapement,
    INT cOrientation,
    INT cWeight,
    DWORD bItalic,
    DWORD bUnderline,
    DWORD bStrikeOut,
    DWORD iCharSet,
    DWORD iOutPrecision,
    DWORD iClipPrecision,
    DWORD iQuality,
    DWORD iPitchAndFamily,
    LPCWSTR pszFaceName   // optional
);

パラメーター

名前方向
cHeightINTin
cWidthINTin
cEscapementINTin
cOrientationINTin
cWeightINTin
bItalicDWORDin
bUnderlineDWORDin
bStrikeOutDWORDin
iCharSetDWORDin
iOutPrecisionDWORDin
iClipPrecisionDWORDin
iQualityDWORDin
iPitchAndFamilyDWORDin
pszFaceNameLPCWSTRinoptional

戻り値の型: HFONT

各言語での呼び出し定義

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

HFONT CreateFontW(
    INT cHeight,
    INT cWidth,
    INT cEscapement,
    INT cOrientation,
    INT cWeight,
    DWORD bItalic,
    DWORD bUnderline,
    DWORD bStrikeOut,
    DWORD iCharSet,
    DWORD iOutPrecision,
    DWORD iClipPrecision,
    DWORD iQuality,
    DWORD iPitchAndFamily,
    LPCWSTR pszFaceName   // optional
);
[DllImport("GDI32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern IntPtr CreateFontW(
    int cHeight,   // INT
    int cWidth,   // INT
    int cEscapement,   // INT
    int cOrientation,   // INT
    int cWeight,   // INT
    uint bItalic,   // DWORD
    uint bUnderline,   // DWORD
    uint bStrikeOut,   // DWORD
    uint iCharSet,   // DWORD
    uint iOutPrecision,   // DWORD
    uint iClipPrecision,   // DWORD
    uint iQuality,   // DWORD
    uint iPitchAndFamily,   // DWORD
    [MarshalAs(UnmanagedType.LPWStr)] string pszFaceName   // LPCWSTR optional
);
<DllImport("GDI32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function CreateFontW(
    cHeight As Integer,   ' INT
    cWidth As Integer,   ' INT
    cEscapement As Integer,   ' INT
    cOrientation As Integer,   ' INT
    cWeight As Integer,   ' INT
    bItalic As UInteger,   ' DWORD
    bUnderline As UInteger,   ' DWORD
    bStrikeOut As UInteger,   ' DWORD
    iCharSet As UInteger,   ' DWORD
    iOutPrecision As UInteger,   ' DWORD
    iClipPrecision As UInteger,   ' DWORD
    iQuality As UInteger,   ' DWORD
    iPitchAndFamily As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPWStr)> pszFaceName As String   ' LPCWSTR optional
) As IntPtr
End Function
' cHeight : INT
' cWidth : INT
' cEscapement : INT
' cOrientation : INT
' cWeight : INT
' bItalic : DWORD
' bUnderline : DWORD
' bStrikeOut : DWORD
' iCharSet : DWORD
' iOutPrecision : DWORD
' iClipPrecision : DWORD
' iQuality : DWORD
' iPitchAndFamily : DWORD
' pszFaceName : LPCWSTR optional
Declare PtrSafe Function CreateFontW Lib "gdi32" ( _
    ByVal cHeight As Long, _
    ByVal cWidth As Long, _
    ByVal cEscapement As Long, _
    ByVal cOrientation As Long, _
    ByVal cWeight As Long, _
    ByVal bItalic As Long, _
    ByVal bUnderline As Long, _
    ByVal bStrikeOut As Long, _
    ByVal iCharSet As Long, _
    ByVal iOutPrecision As Long, _
    ByVal iClipPrecision As Long, _
    ByVal iQuality As Long, _
    ByVal iPitchAndFamily As Long, _
    ByVal pszFaceName 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

CreateFontW = ctypes.windll.gdi32.CreateFontW
CreateFontW.restype = ctypes.c_void_p
CreateFontW.argtypes = [
    ctypes.c_int,  # cHeight : INT
    ctypes.c_int,  # cWidth : INT
    ctypes.c_int,  # cEscapement : INT
    ctypes.c_int,  # cOrientation : INT
    ctypes.c_int,  # cWeight : INT
    wintypes.DWORD,  # bItalic : DWORD
    wintypes.DWORD,  # bUnderline : DWORD
    wintypes.DWORD,  # bStrikeOut : DWORD
    wintypes.DWORD,  # iCharSet : DWORD
    wintypes.DWORD,  # iOutPrecision : DWORD
    wintypes.DWORD,  # iClipPrecision : DWORD
    wintypes.DWORD,  # iQuality : DWORD
    wintypes.DWORD,  # iPitchAndFamily : DWORD
    wintypes.LPCWSTR,  # pszFaceName : LPCWSTR optional
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('GDI32.dll')
CreateFontW = Fiddle::Function.new(
  lib['CreateFontW'],
  [
    Fiddle::TYPE_INT,  # cHeight : INT
    Fiddle::TYPE_INT,  # cWidth : INT
    Fiddle::TYPE_INT,  # cEscapement : INT
    Fiddle::TYPE_INT,  # cOrientation : INT
    Fiddle::TYPE_INT,  # cWeight : INT
    -Fiddle::TYPE_INT,  # bItalic : DWORD
    -Fiddle::TYPE_INT,  # bUnderline : DWORD
    -Fiddle::TYPE_INT,  # bStrikeOut : DWORD
    -Fiddle::TYPE_INT,  # iCharSet : DWORD
    -Fiddle::TYPE_INT,  # iOutPrecision : DWORD
    -Fiddle::TYPE_INT,  # iClipPrecision : DWORD
    -Fiddle::TYPE_INT,  # iQuality : DWORD
    -Fiddle::TYPE_INT,  # iPitchAndFamily : DWORD
    Fiddle::TYPE_VOIDP,  # pszFaceName : LPCWSTR optional
  ],
  Fiddle::TYPE_VOIDP)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "gdi32")]
extern "system" {
    fn CreateFontW(
        cHeight: i32,  // INT
        cWidth: i32,  // INT
        cEscapement: i32,  // INT
        cOrientation: i32,  // INT
        cWeight: i32,  // INT
        bItalic: u32,  // DWORD
        bUnderline: u32,  // DWORD
        bStrikeOut: u32,  // DWORD
        iCharSet: u32,  // DWORD
        iOutPrecision: u32,  // DWORD
        iClipPrecision: u32,  // DWORD
        iQuality: u32,  // DWORD
        iPitchAndFamily: u32,  // DWORD
        pszFaceName: *const u16  // LPCWSTR optional
    ) -> *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 CreateFontW(int cHeight, int cWidth, int cEscapement, int cOrientation, int cWeight, uint bItalic, uint bUnderline, uint bStrikeOut, uint iCharSet, uint iOutPrecision, uint iClipPrecision, uint iQuality, uint iPitchAndFamily, [MarshalAs(UnmanagedType.LPWStr)] string pszFaceName);
"@
$api = Add-Type -MemberDefinition $sig -Name 'GDI32_CreateFontW' -Namespace Win32 -PassThru
# $api::CreateFontW(cHeight, cWidth, cEscapement, cOrientation, cWeight, bItalic, bUnderline, bStrikeOut, iCharSet, iOutPrecision, iClipPrecision, iQuality, iPitchAndFamily, pszFaceName)
#uselib "GDI32.dll"
#func global CreateFontW "CreateFontW" wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr
; CreateFontW cHeight, cWidth, cEscapement, cOrientation, cWeight, bItalic, bUnderline, bStrikeOut, iCharSet, iOutPrecision, iClipPrecision, iQuality, iPitchAndFamily, pszFaceName   ; 戻り値は stat
; cHeight : INT -> "wptr"
; cWidth : INT -> "wptr"
; cEscapement : INT -> "wptr"
; cOrientation : INT -> "wptr"
; cWeight : INT -> "wptr"
; bItalic : DWORD -> "wptr"
; bUnderline : DWORD -> "wptr"
; bStrikeOut : DWORD -> "wptr"
; iCharSet : DWORD -> "wptr"
; iOutPrecision : DWORD -> "wptr"
; iClipPrecision : DWORD -> "wptr"
; iQuality : DWORD -> "wptr"
; iPitchAndFamily : DWORD -> "wptr"
; pszFaceName : LPCWSTR optional -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "GDI32.dll"
#cfunc global CreateFontW "CreateFontW" int, int, int, int, int, int, int, int, int, int, int, int, int, wstr
; res = CreateFontW(cHeight, cWidth, cEscapement, cOrientation, cWeight, bItalic, bUnderline, bStrikeOut, iCharSet, iOutPrecision, iClipPrecision, iQuality, iPitchAndFamily, pszFaceName)
; cHeight : INT -> "int"
; cWidth : INT -> "int"
; cEscapement : INT -> "int"
; cOrientation : INT -> "int"
; cWeight : INT -> "int"
; bItalic : DWORD -> "int"
; bUnderline : DWORD -> "int"
; bStrikeOut : DWORD -> "int"
; iCharSet : DWORD -> "int"
; iOutPrecision : DWORD -> "int"
; iClipPrecision : DWORD -> "int"
; iQuality : DWORD -> "int"
; iPitchAndFamily : DWORD -> "int"
; pszFaceName : LPCWSTR optional -> "wstr"
; HFONT CreateFontW(INT cHeight, INT cWidth, INT cEscapement, INT cOrientation, INT cWeight, DWORD bItalic, DWORD bUnderline, DWORD bStrikeOut, DWORD iCharSet, DWORD iOutPrecision, DWORD iClipPrecision, DWORD iQuality, DWORD iPitchAndFamily, LPCWSTR pszFaceName)
#uselib "GDI32.dll"
#cfunc global CreateFontW "CreateFontW" int, int, int, int, int, int, int, int, int, int, int, int, int, wstr
; res = CreateFontW(cHeight, cWidth, cEscapement, cOrientation, cWeight, bItalic, bUnderline, bStrikeOut, iCharSet, iOutPrecision, iClipPrecision, iQuality, iPitchAndFamily, pszFaceName)
; cHeight : INT -> "int"
; cWidth : INT -> "int"
; cEscapement : INT -> "int"
; cOrientation : INT -> "int"
; cWeight : INT -> "int"
; bItalic : DWORD -> "int"
; bUnderline : DWORD -> "int"
; bStrikeOut : DWORD -> "int"
; iCharSet : DWORD -> "int"
; iOutPrecision : DWORD -> "int"
; iClipPrecision : DWORD -> "int"
; iQuality : DWORD -> "int"
; iPitchAndFamily : DWORD -> "int"
; pszFaceName : LPCWSTR optional -> "wstr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	gdi32 = windows.NewLazySystemDLL("GDI32.dll")
	procCreateFontW = gdi32.NewProc("CreateFontW")
)

// cHeight (INT), cWidth (INT), cEscapement (INT), cOrientation (INT), cWeight (INT), bItalic (DWORD), bUnderline (DWORD), bStrikeOut (DWORD), iCharSet (DWORD), iOutPrecision (DWORD), iClipPrecision (DWORD), iQuality (DWORD), iPitchAndFamily (DWORD), pszFaceName (LPCWSTR optional)
r1, _, err := procCreateFontW.Call(
	uintptr(cHeight),
	uintptr(cWidth),
	uintptr(cEscapement),
	uintptr(cOrientation),
	uintptr(cWeight),
	uintptr(bItalic),
	uintptr(bUnderline),
	uintptr(bStrikeOut),
	uintptr(iCharSet),
	uintptr(iOutPrecision),
	uintptr(iClipPrecision),
	uintptr(iQuality),
	uintptr(iPitchAndFamily),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszFaceName))),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HFONT
function CreateFontW(
  cHeight: Integer;   // INT
  cWidth: Integer;   // INT
  cEscapement: Integer;   // INT
  cOrientation: Integer;   // INT
  cWeight: Integer;   // INT
  bItalic: DWORD;   // DWORD
  bUnderline: DWORD;   // DWORD
  bStrikeOut: DWORD;   // DWORD
  iCharSet: DWORD;   // DWORD
  iOutPrecision: DWORD;   // DWORD
  iClipPrecision: DWORD;   // DWORD
  iQuality: DWORD;   // DWORD
  iPitchAndFamily: DWORD;   // DWORD
  pszFaceName: PWideChar   // LPCWSTR optional
): THandle; stdcall;
  external 'GDI32.dll' name 'CreateFontW';
result := DllCall("GDI32\CreateFontW"
    , "Int", cHeight   ; INT
    , "Int", cWidth   ; INT
    , "Int", cEscapement   ; INT
    , "Int", cOrientation   ; INT
    , "Int", cWeight   ; INT
    , "UInt", bItalic   ; DWORD
    , "UInt", bUnderline   ; DWORD
    , "UInt", bStrikeOut   ; DWORD
    , "UInt", iCharSet   ; DWORD
    , "UInt", iOutPrecision   ; DWORD
    , "UInt", iClipPrecision   ; DWORD
    , "UInt", iQuality   ; DWORD
    , "UInt", iPitchAndFamily   ; DWORD
    , "WStr", pszFaceName   ; LPCWSTR optional
    , "Ptr")   ; return: HFONT
●CreateFontW(cHeight, cWidth, cEscapement, cOrientation, cWeight, bItalic, bUnderline, bStrikeOut, iCharSet, iOutPrecision, iClipPrecision, iQuality, iPitchAndFamily, pszFaceName) = DLL("GDI32.dll", "void* CreateFontW(int, int, int, int, int, dword, dword, dword, dword, dword, dword, dword, dword, char*)")
# 呼び出し: CreateFontW(cHeight, cWidth, cEscapement, cOrientation, cWeight, bItalic, bUnderline, bStrikeOut, iCharSet, iOutPrecision, iClipPrecision, iQuality, iPitchAndFamily, pszFaceName)
# cHeight : INT -> "int"
# cWidth : INT -> "int"
# cEscapement : INT -> "int"
# cOrientation : INT -> "int"
# cWeight : INT -> "int"
# bItalic : DWORD -> "dword"
# bUnderline : DWORD -> "dword"
# bStrikeOut : DWORD -> "dword"
# iCharSet : DWORD -> "dword"
# iOutPrecision : DWORD -> "dword"
# iClipPrecision : DWORD -> "dword"
# iQuality : DWORD -> "dword"
# iPitchAndFamily : DWORD -> "dword"
# pszFaceName : LPCWSTR optional -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。