ホーム › Graphics.Gdi › GetTextFaceA
GetTextFaceA
関数現在選択中のフォントの書体名を取得する(ANSI版)。
シグネチャ
// GDI32.dll (ANSI / -A)
#include <windows.h>
INT GetTextFaceA(
HDC hdc,
INT c,
LPSTR lpName // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hdc | HDC | in | デバイスコンテキストへのハンドル。 |
| c | INT | in | lpFaceName が指すバッファの長さ。ANSI 関数では BYTE 数、Unicode 関数では WORD 数です。なお、ANSI 関数では SBCS コードページの文字は 1 文字あたり 1 バイトですが、DBCS コードページのほとんどの文字は 2 バイトを使用します。Unicode 関数では、現在定義されているほとんどの Unicode 文字(基本多言語面 (BMP) に含まれる文字)は 1 WORD ですが、Unicode サロゲートは 2 WORD です。 |
| lpName | LPSTR | outoptional | 書体名を受け取るバッファへのポインター。このパラメーターが NULL の場合、関数は終端の null 文字を含む名前の文字数を返します。 |
戻り値の型: INT
公式ドキュメント
GetTextFace 関数は、指定したデバイスコンテキストに選択されているフォントの書体名を取得します。(ANSI)
戻り値
関数が成功すると、戻り値はバッファにコピーされた文字数です。
関数が失敗すると、戻り値は 0 です。
解説(Remarks)
書体名は null で終わる文字列としてコピーされます。
名前が nCount パラメーターで指定された文字数より長い場合、名前は切り詰められます。
メモ
wingdi.h ヘッダーは GetTextFace を、UNICODE プリプロセッサ定数の定義に基づいてこの関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして定義します。エンコーディング非依存のエイリアスを、エンコーディング非依存でないコードと混在させて使用すると、不一致が生じ、コンパイルエラーや実行時エラーの原因となることがあります。詳細については、Conventions for Function Prototypes を参照してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// 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 方式にも切替可。#uselib "GDI32.dll" #cfunc global GetTextFaceA "GetTextFaceA" sptr, int, sptr ; res = GetTextFaceA(hdc, c, varptr(lpName)) ; hdc : HDC -> "sptr" ; c : INT -> "int" ; lpName : LPSTR optional, out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは 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 方式にも切替可。; INT GetTextFaceA(HDC hdc, INT c, LPSTR lpName) #uselib "GDI32.dll" #cfunc global GetTextFaceA "GetTextFaceA" intptr, int, intptr ; res = GetTextFaceA(hdc, c, varptr(lpName)) ; hdc : HDC -> "intptr" ; c : INT -> "int" ; lpName : LPSTR optional, out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは 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 // INTfunction 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)。const std = @import("std");
extern "gdi32" fn GetTextFaceA(
hdc: ?*anyopaque, // HDC
c: i32, // INT
lpName: [*c]u8 // LPSTR optional, out
) callconv(std.os.windows.WINAPI) i32;proc GetTextFaceA(
hdc: pointer, # HDC
c: int32, # INT
lpName: ptr char # LPSTR optional, out
): int32 {.importc: "GetTextFaceA", stdcall, dynlib: "GDI32.dll".}pragma(lib, "gdi32");
extern(Windows)
int GetTextFaceA(
void* hdc, // HDC
int c, // INT
char* lpName // LPSTR optional, out
);ccall((:GetTextFaceA, "GDI32.dll"), stdcall, Int32,
(Ptr{Cvoid}, Int32, Ptr{UInt8}),
hdc, c, lpName)
# hdc : HDC -> Ptr{Cvoid}
# c : INT -> Int32
# lpName : LPSTR optional, out -> Ptr{UInt8}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t GetTextFaceA(
void* hdc,
int32_t c,
char* lpName);
]]
local gdi32 = ffi.load("gdi32")
-- gdi32.GetTextFaceA(hdc, c, lpName)
-- hdc : HDC
-- c : INT
-- lpName : LPSTR optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('GDI32.dll');
const GetTextFaceA = lib.func('__stdcall', 'GetTextFaceA', 'int32_t', ['void *', 'int32_t', 'char *']);
// GetTextFaceA(hdc, c, lpName)
// hdc : HDC -> 'void *'
// c : INT -> 'int32_t'
// lpName : LPSTR optional, out -> 'char *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("GDI32.dll", {
GetTextFaceA: { parameters: ["pointer", "i32", "buffer"], result: "i32" },
});
// lib.symbols.GetTextFaceA(hdc, c, lpName)
// hdc : HDC -> "pointer"
// c : INT -> "i32"
// lpName : LPSTR optional, out -> "buffer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t GetTextFaceA(
void* hdc,
int32_t c,
char* lpName);
C, "GDI32.dll");
// $ffi->GetTextFaceA(hdc, c, lpName);
// hdc : HDC
// c : INT
// lpName : LPSTR optional, out
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Gdi32 extends StdCallLibrary {
Gdi32 INSTANCE = Native.load("gdi32", Gdi32.class, W32APIOptions.ASCII_OPTIONS);
int GetTextFaceA(
Pointer hdc, // HDC
int c, // INT
byte[] lpName // LPSTR optional, out
);
}@[Link("gdi32")]
lib LibGDI32
fun GetTextFaceA = GetTextFaceA(
hdc : Void*, # HDC
c : Int32, # INT
lpName : UInt8* # LPSTR optional, out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef GetTextFaceANative = Int32 Function(Pointer<Void>, Int32, Pointer<Utf8>);
typedef GetTextFaceADart = int Function(Pointer<Void>, int, Pointer<Utf8>);
final GetTextFaceA = DynamicLibrary.open('GDI32.dll')
.lookupFunction<GetTextFaceANative, GetTextFaceADart>('GetTextFaceA');
// hdc : HDC -> Pointer<Void>
// c : INT -> Int32
// lpName : LPSTR optional, out -> Pointer<Utf8>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function GetTextFaceA(
hdc: THandle; // HDC
c: Integer; // INT
lpName: PAnsiChar // LPSTR optional, out
): Integer; stdcall;
external 'GDI32.dll' name 'GetTextFaceA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "GetTextFaceA"
c_GetTextFaceA :: Ptr () -> Int32 -> CString -> IO Int32
-- hdc : HDC -> Ptr ()
-- c : INT -> Int32
-- lpName : LPSTR optional, out -> CString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let gettextfacea =
foreign "GetTextFaceA"
((ptr void) @-> int32_t @-> string @-> returning int32_t)
(* hdc : HDC -> (ptr void) *)
(* c : INT -> int32_t *)
(* lpName : LPSTR optional, out -> string *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library gdi32 (t "GDI32.dll"))
(cffi:use-foreign-library gdi32)
(cffi:defcfun ("GetTextFaceA" get-text-face-a :convention :stdcall) :int32
(hdc :pointer) ; HDC
(c :int32) ; INT
(lp-name :pointer)) ; LPSTR optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $GetTextFaceA = Win32::API::More->new('GDI32',
'int GetTextFaceA(HANDLE hdc, int c, LPSTR lpName)');
# my $ret = $GetTextFaceA->Call($hdc, $c, $lpName);
# hdc : HDC -> HANDLE
# c : INT -> int
# lpName : LPSTR optional, out -> LPSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
文字セット違い
- f GetTextFaceW (Unicode版) — 現在選択中のフォントの書体名を取得する(Unicode版)。
公式の関連項目
- f GetTextAlign — DCの現在のテキスト配置設定を取得する。
- f GetTextColor — DCの現在のテキスト色を取得する。
- f GetTextExtentPoint32A — 文字列を描画した際の幅と高さを取得する。