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

GetTextFaceA

関数
現在選択中のフォントの書体名を取得する(ANSI版)。
DLLGDI32.dll文字セットANSI (-A)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

INT GetTextFaceA(
    HDC hdc,
    INT c,
    LPSTR lpName   // optional
);

パラメーター

名前方向
hdcHDCin
cINTin
lpNameLPSTRoutoptional

戻り値の型: INT

各言語での呼び出し定義

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

INT GetTextFaceA(
    HDC hdc,
    INT c,
    LPSTR lpName   // optional
);
[DllImport("GDI32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern int GetTextFaceA(
    IntPtr hdc,   // HDC
    int c,   // INT
    [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpName   // LPSTR optional, out
);
<DllImport("GDI32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function GetTextFaceA(
    hdc As IntPtr,   ' HDC
    c As Integer,   ' INT
    <MarshalAs(UnmanagedType.LPStr)> lpName As System.Text.StringBuilder   ' LPSTR optional, out
) As Integer
End Function
' hdc : HDC
' c : INT
' lpName : LPSTR optional, out
Declare PtrSafe Function GetTextFaceA Lib "gdi32" ( _
    ByVal hdc As LongPtr, _
    ByVal c As Long, _
    ByVal lpName As String) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetTextFaceA = ctypes.windll.gdi32.GetTextFaceA
GetTextFaceA.restype = ctypes.c_int
GetTextFaceA.argtypes = [
    wintypes.HANDLE,  # hdc : HDC
    ctypes.c_int,  # c : INT
    wintypes.LPSTR,  # lpName : LPSTR optional, out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('GDI32.dll')
GetTextFaceA = Fiddle::Function.new(
  lib['GetTextFaceA'],
  [
    Fiddle::TYPE_VOIDP,  # hdc : HDC
    Fiddle::TYPE_INT,  # c : INT
    Fiddle::TYPE_VOIDP,  # lpName : LPSTR optional, out
  ],
  Fiddle::TYPE_INT)
#[link(name = "gdi32")]
extern "system" {
    fn GetTextFaceA(
        hdc: *mut core::ffi::c_void,  // HDC
        c: i32,  // INT
        lpName: *mut u8  // LPSTR optional, out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("GDI32.dll", CharSet = CharSet.Ansi)]
public static extern int GetTextFaceA(IntPtr hdc, int c, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpName);
"@
$api = Add-Type -MemberDefinition $sig -Name 'GDI32_GetTextFaceA' -Namespace Win32 -PassThru
# $api::GetTextFaceA(hdc, c, lpName)
#uselib "GDI32.dll"
#func global GetTextFaceA "GetTextFaceA" sptr, sptr, sptr
; GetTextFaceA hdc, c, varptr(lpName)   ; 戻り値は stat
; hdc : HDC -> "sptr"
; c : INT -> "sptr"
; lpName : LPSTR optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "GDI32.dll"
#cfunc global GetTextFaceA "GetTextFaceA" sptr, int, var
; res = GetTextFaceA(hdc, c, lpName)
; hdc : HDC -> "sptr"
; c : INT -> "int"
; lpName : LPSTR optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; INT GetTextFaceA(HDC hdc, INT c, LPSTR lpName)
#uselib "GDI32.dll"
#cfunc global GetTextFaceA "GetTextFaceA" intptr, int, var
; res = GetTextFaceA(hdc, c, lpName)
; hdc : HDC -> "intptr"
; c : INT -> "int"
; lpName : LPSTR optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	gdi32 = windows.NewLazySystemDLL("GDI32.dll")
	procGetTextFaceA = gdi32.NewProc("GetTextFaceA")
)

// hdc (HDC), c (INT), lpName (LPSTR optional, out)
r1, _, err := procGetTextFaceA.Call(
	uintptr(hdc),
	uintptr(c),
	uintptr(lpName),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INT
function GetTextFaceA(
  hdc: THandle;   // HDC
  c: Integer;   // INT
  lpName: PAnsiChar   // LPSTR optional, out
): Integer; stdcall;
  external 'GDI32.dll' name 'GetTextFaceA';
result := DllCall("GDI32\GetTextFaceA"
    , "Ptr", hdc   ; HDC
    , "Int", c   ; INT
    , "Ptr", lpName   ; LPSTR optional, out
    , "Int")   ; return: INT
●GetTextFaceA(hdc, c, lpName) = DLL("GDI32.dll", "int GetTextFaceA(void*, int, char*)")
# 呼び出し: GetTextFaceA(hdc, c, lpName)
# hdc : HDC -> "void*"
# c : INT -> "int"
# lpName : LPSTR optional, out -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。