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

CreateFontA

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

シグネチャ

// GDI32.dll  (ANSI / -A)
#include <windows.h>

HFONT CreateFontA(
    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,
    LPCSTR pszFaceName   // optional
);

パラメーター

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

戻り値の型: HFONT

各言語での呼び出し定義

// GDI32.dll  (ANSI / -A)
#include <windows.h>

HFONT CreateFontA(
    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,
    LPCSTR pszFaceName   // optional
);
[DllImport("GDI32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern IntPtr CreateFontA(
    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.LPStr)] string pszFaceName   // LPCSTR optional
);
<DllImport("GDI32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function CreateFontA(
    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.LPStr)> pszFaceName As String   ' LPCSTR 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 : LPCSTR optional
Declare PtrSafe Function CreateFontA 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 String) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

CreateFontA = ctypes.windll.gdi32.CreateFontA
CreateFontA.restype = ctypes.c_void_p
CreateFontA.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.LPCSTR,  # pszFaceName : LPCSTR optional
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('GDI32.dll')
CreateFontA = Fiddle::Function.new(
  lib['CreateFontA'],
  [
    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 : LPCSTR optional
  ],
  Fiddle::TYPE_VOIDP)
#[link(name = "gdi32")]
extern "system" {
    fn CreateFontA(
        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 u8  // LPCSTR optional
    ) -> *mut core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("GDI32.dll", CharSet = CharSet.Ansi)]
public static extern IntPtr CreateFontA(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.LPStr)] string pszFaceName);
"@
$api = Add-Type -MemberDefinition $sig -Name 'GDI32_CreateFontA' -Namespace Win32 -PassThru
# $api::CreateFontA(cHeight, cWidth, cEscapement, cOrientation, cWeight, bItalic, bUnderline, bStrikeOut, iCharSet, iOutPrecision, iClipPrecision, iQuality, iPitchAndFamily, pszFaceName)
#uselib "GDI32.dll"
#func global CreateFontA "CreateFontA" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; CreateFontA cHeight, cWidth, cEscapement, cOrientation, cWeight, bItalic, bUnderline, bStrikeOut, iCharSet, iOutPrecision, iClipPrecision, iQuality, iPitchAndFamily, pszFaceName   ; 戻り値は stat
; cHeight : INT -> "sptr"
; cWidth : INT -> "sptr"
; cEscapement : INT -> "sptr"
; cOrientation : INT -> "sptr"
; cWeight : INT -> "sptr"
; bItalic : DWORD -> "sptr"
; bUnderline : DWORD -> "sptr"
; bStrikeOut : DWORD -> "sptr"
; iCharSet : DWORD -> "sptr"
; iOutPrecision : DWORD -> "sptr"
; iClipPrecision : DWORD -> "sptr"
; iQuality : DWORD -> "sptr"
; iPitchAndFamily : DWORD -> "sptr"
; pszFaceName : LPCSTR optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "GDI32.dll"
#cfunc global CreateFontA "CreateFontA" int, int, int, int, int, int, int, int, int, int, int, int, int, str
; res = CreateFontA(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 : LPCSTR optional -> "str"
; HFONT CreateFontA(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, LPCSTR pszFaceName)
#uselib "GDI32.dll"
#cfunc global CreateFontA "CreateFontA" int, int, int, int, int, int, int, int, int, int, int, int, int, str
; res = CreateFontA(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 : LPCSTR optional -> "str"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	gdi32 = windows.NewLazySystemDLL("GDI32.dll")
	procCreateFontA = gdi32.NewProc("CreateFontA")
)

// 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 (LPCSTR optional)
r1, _, err := procCreateFontA.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.BytePtrFromString(pszFaceName))),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HFONT
function CreateFontA(
  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: PAnsiChar   // LPCSTR optional
): THandle; stdcall;
  external 'GDI32.dll' name 'CreateFontA';
result := DllCall("GDI32\CreateFontA"
    , "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
    , "AStr", pszFaceName   ; LPCSTR optional
    , "Ptr")   ; return: HFONT
●CreateFontA(cHeight, cWidth, cEscapement, cOrientation, cWeight, bItalic, bUnderline, bStrikeOut, iCharSet, iOutPrecision, iClipPrecision, iQuality, iPitchAndFamily, pszFaceName) = DLL("GDI32.dll", "void* CreateFontA(int, int, int, int, int, dword, dword, dword, dword, dword, dword, dword, dword, char*)")
# 呼び出し: CreateFontA(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 : LPCSTR optional -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。