CreateFontA
関数シグネチャ
// 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
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| cHeight | INT | in | フォントの文字セルまたは文字の高さ(論理単位)。文字の高さの値(em の高さとも呼ばれます)は、文字セルの高さの値から内部レディング値を引いた値です。フォントマッパーは、nHeight に指定された値を次のように解釈します。
すべての高さの比較において、フォントマッパーは要求されたサイズを超えない範囲で最大のフォントを探します。 このマッピングは、フォントが初めて使用されるときに行われます。 MM_TEXT マッピングモードでは、次の式を使用して、指定したポイントサイズのフォントの高さを指定できます。 | ||||||||||||||||||||||||||||||||
| cWidth | INT | in | 要求するフォントの文字の平均幅(論理単位)。この値が 0 の場合、フォントマッパーは最も近い一致値を選択します。最も近い一致値は、現在のデバイスのアスペクト比と、利用可能なフォントのデジタイズされたアスペクト比との差の絶対値を比較して決定されます。 | ||||||||||||||||||||||||||||||||
| cEscapement | INT | in | エスケープメントベクトルとデバイスの x 軸との間の角度(度の 1/10 単位)。エスケープメントベクトルは、テキスト行のベースラインに平行です。 グラフィックスモードが GM_ADVANCED に設定されている場合は、文字列の文字の向き角度とは独立して、文字列のエスケープメント角度を指定できます。 グラフィックスモードが GM_COMPATIBLE に設定されている場合、nEscapement はエスケープメントと向きの両方を指定します。nEscapement と nOrientation には同じ値を設定してください。 | ||||||||||||||||||||||||||||||||
| cOrientation | INT | in | 各文字のベースラインとデバイスの x 軸との間の角度(度の 1/10 単位)。 | ||||||||||||||||||||||||||||||||
| cWeight | INT | in | フォントの太さ。0 から 1000 の範囲で指定します。たとえば、400 は標準、700 は太字です。この値が 0 の場合は、既定の太さが使用されます。 便宜のために次の値が定義されています。
| ||||||||||||||||||||||||||||||||
| bItalic | DWORD | in | TRUE に設定すると、イタリック体のフォントを指定します。 | ||||||||||||||||||||||||||||||||
| bUnderline | DWORD | in | TRUE に設定すると、下線付きのフォントを指定します。 | ||||||||||||||||||||||||||||||||
| bStrikeOut | DWORD | in | TRUE に設定すると、取り消し線付きのフォントを指定します。 | ||||||||||||||||||||||||||||||||
| iCharSet | DWORD | in | 文字セット。指定可能な値の一覧については、LOGFONT 構造体の lfCharSet フィールドを参照してください。 オペレーティングシステムには、他の文字セットを持つフォントが存在する場合があります。アプリケーションが不明な文字セットのフォントを使用する場合、そのフォントで描画される文字列を変換または解釈しようとしないでください。 フォントを作成する際に一貫した結果を得るため、OEM_CHARSET や DEFAULT_CHARSET を指定しないでください。pszFaceName パラメーターに書体名を指定する場合は、iCharSet の値が pszFaceName で指定した書体の文字セットと一致していることを確認してください。 | ||||||||||||||||||||||||||||||||
| iOutPrecision | DWORD | in | 出力精度。出力精度は、要求されたフォントの高さ、幅、文字の向き、エスケープメント、ピッチ、フォントの種類に対して、出力をどの程度厳密に一致させる必要があるかを定義します。次のいずれかの値を指定できます。 アプリケーションは、オペレーティングシステムに指定した名前のフォントが複数含まれている場合に、フォントマッパーがどのようにフォントを選択するかを制御するために、OUT_DEVICE_PRECIS、OUT_RASTER_PRECIS、OUT_TT_PRECIS、OUT_PS_ONLY_PRECIS の各値を使用できます。たとえば、オペレーティングシステムに Symbol という名前のフォントがラスター形式と TrueType 形式の両方で含まれている場合、OUT_TT_PRECIS を指定すると、フォントマッパーは TrueType 版を選択します。OUT_TT_ONLY_PRECIS を指定すると、別の名前の TrueType フォントを代用してでも、フォントマッパーは TrueType フォントを選択します。 | ||||||||||||||||||||||||||||||||
| iClipPrecision | DWORD | in | クリッピング精度。クリッピング精度は、クリッピング領域の一部からはみ出した文字をどのようにクリップするかを定義します。次の値の 1 つ以上を指定できます。
| ||||||||||||||||||||||||||||||||
| iQuality | DWORD | in | 出力品質。出力品質は、論理フォントの属性を実際の物理フォントの属性にどの程度入念に一致させようとするかを GDI に対して定義します。次のいずれかの値を指定できます。
出力品質が DEFAULT_QUALITY、DRAFT_QUALITY、または PROOF_QUALITY の場合、SPI_GETFONTSMOOTHING システムパラメーターが TRUE であれば、フォントはアンチエイリアス処理されます。ユーザーはこのシステムパラメーターをコントロールパネルから制御できます。(コントロールパネルでの設定の正確な表現は Windows のバージョンによって異なりますが、「スクリーンフォントの縁を滑らかにする」といった趣旨の文言になります。) | ||||||||||||||||||||||||||||||||
| iPitchAndFamily | DWORD | in | フォントのピッチとファミリ。下位 2 ビットはフォントのピッチを指定し、次のいずれかの値を指定できます。 上位 4 ビットはフォントファミリを指定し、次のいずれかの値を指定できます。アプリケーションは、ピッチ定数とファミリ定数をブール OR 演算子で結合することにより、fdwPitchAndFamily パラメーターの値を指定できます。 フォントファミリは、フォントの見た目を大まかに表します。これらは、要求した正確な書体が利用できない場合にフォントを指定するためのものです。 | ||||||||||||||||||||||||||||||||
| pszFaceName | LPCSTR | inoptional | フォントの書体名を指定する null 終端文字列へのポインター。この文字列の長さは、終端の null 文字を含めて 32 文字を超えてはなりません。EnumFontFamilies 関数を使用すると、現在利用可能なすべてのフォントの書体名を列挙できます。詳細については「解説」を参照してください。 pszFaceName が NULL または空文字列の場合、GDI は他に指定された属性に一致する最初のフォントを使用します。 |
戻り値の型: HFONT
公式ドキュメント
CreateFont 関数は、指定した特性を持つ論理フォントを作成します。作成した論理フォントは、その後、任意のデバイス用のフォントとして選択できます。(ANSI)
戻り値
関数が成功した場合、戻り値は論理フォントのハンドルです。
関数が失敗した場合、戻り値は NULL です。
解説(Remarks)
フォントが不要になったら、DeleteObject 関数を呼び出してフォントを削除してください。
Windows 向けにフォントを提供するベンダーの著作権を保護するため、アプリケーションは常に、選択されたフォントの正確な名前を報告する必要があります。利用可能なフォントはシステムごとに異なる場合があるため、選択されたフォントが常に要求したフォントと同じであるとは想定しないでください。たとえば、Palatino という名前のフォントを要求しても、そのフォントがシステムに存在しない場合、フォントマッパーは類似した属性を持つ別の名前のフォントを代用します。選択されたフォントの名前は、常にユーザーに報告してください。
さまざまな言語バージョンの OS で適切なフォントを取得するには、LOGFONT 構造体に目的のフォント特性を指定して EnumFontFamiliesEx を呼び出し、適切な書体名を取得してから、CreateFont または CreateFontIndirect を使用してフォントを作成します。
CreateFont、CreateFontIndirect、CreateFontIndirectEx のフォントマッパーは、ロケールに関係なく、英語名とローカライズされた書体名の両方を認識します。
次の状況では ClearType アンチエイリアスはサポートされません。
- プリンターで描画されるテキスト。
- 256 色以下に設定されたディスプレイ。
- ターミナルサーバークライアントに描画されるテキスト。
- フォントが TrueType フォントでも、TrueType アウトラインを持つ OpenType フォントでもない場合。たとえば、Type 1 フォント、TrueType アウトラインを持たない PostScript OpenType フォント、ビットマップフォント、ベクターフォント、デバイスフォントは ClearType アンチエイリアスをサポートしません。
- フォントが調整済みの埋め込みビットマップを持つ場合、その埋め込みビットマップを含むフォントサイズに限ります。たとえば、これは東アジアのフォントでよく見られます。
例
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
switch (message)
{
case WM_PAINT:
{
RECT rect;
HFONT hFontOriginal, hFont1, hFont2, hFont3;
hdc = BeginPaint(hWnd, &ps);
//Logical units are device dependent pixels, so this will create a handle to a logical font that is 48 pixels in height.
//The width, when set to 0, will cause the font mapper to choose the closest matching value.
//The font face name will be Impact.
hFont1 = CreateFont(48,0,0,0,FW_DONTCARE,FALSE,TRUE,FALSE,DEFAULT_CHARSET,OUT_OUTLINE_PRECIS,
CLIP_DEFAULT_PRECIS,CLEARTYPE_QUALITY, VARIABLE_PITCH,TEXT("Impact"));
hFontOriginal = (HFONT)SelectObject(hdc, hFont1);
//Sets the coordinates for the rectangle in which the text is to be formatted.
SetRect(&rect, 100,100,700,200);
SetTextColor(hdc, RGB(255,0,0));
DrawText(hdc, TEXT("Drawing Text with Impact"), -1,&rect, DT_NOCLIP);
//Logical units are device dependent pixels, so this will create a handle to a logical font that is 36 pixels in height.
//The width, when set to 20, will cause the font mapper to choose a font which, in this case, is stretched.
//The font face name will be Times New Roman. This time nEscapement is at -300 tenths of a degree (-30 degrees)
hFont2 = CreateFont(36,20,-300,0,FW_DONTCARE,FALSE,TRUE,FALSE,DEFAULT_CHARSET,OUT_OUTLINE_PRECIS,
CLIP_DEFAULT_PRECIS,CLEARTYPE_QUALITY, VARIABLE_PITCH,TEXT("Times New Roman"));
SelectObject(hdc,hFont2);
//Sets the coordinates for the rectangle in which the text is to be formatted.
SetRect(&rect, 100, 200, 900, 800);
SetTextColor(hdc, RGB(0,128,0));
DrawText(hdc, TEXT("Drawing Text with Times New Roman"), -1,&rect, DT_NOCLIP);
//Logical units are device dependent pixels, so this will create a handle to a logical font that is 36 pixels in height.
//The width, when set to 10, will cause the font mapper to choose a font which, in this case, is compressed.
//The font face name will be Arial. This time nEscapement is at 250 tenths of a degree (25 degrees)
hFont3 = CreateFont(36,10,250,0,FW_DONTCARE,FALSE,TRUE,FALSE,DEFAULT_CHARSET,OUT_OUTLINE_PRECIS,
CLIP_DEFAULT_PRECIS,ANTIALIASED_QUALITY, VARIABLE_PITCH,TEXT("Arial"));
SelectObject(hdc,hFont3);
//Sets the coordinates for the rectangle in which the text is to be formatted.
SetRect(&rect, 500, 200, 1400, 600);
SetTextColor(hdc, RGB(0,0,255));
DrawText(hdc, TEXT("Drawing Text with Arial"), -1,&rect, DT_NOCLIP);
SelectObject(hdc,hFontOriginal);
DeleteObject(hFont1);
DeleteObject(hFont2);
DeleteObject(hFont3);
EndPaint(hWnd, &ps);
break;
}
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
もう 1 つの例については、メニューの使用の「Setting Fonts for Menu-Item Text Strings」を参照してください。
wingdi.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして CreateFont を定義します。エンコーディング中立のエイリアスの使用を、エンコーディング中立でないコードと混在させると、不一致が生じ、コンパイルエラーまたは実行時エラーを引き起こす可能性があります。詳細については、関数プロトタイプの規則を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// 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 // HFONTfunction 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)。const std = @import("std");
extern "gdi32" 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: [*c]const u8 // LPCSTR optional
) callconv(std.os.windows.WINAPI) ?*anyopaque;proc CreateFontA(
cHeight: int32, # INT
cWidth: int32, # INT
cEscapement: int32, # INT
cOrientation: int32, # INT
cWeight: int32, # INT
bItalic: uint32, # DWORD
bUnderline: uint32, # DWORD
bStrikeOut: uint32, # DWORD
iCharSet: uint32, # DWORD
iOutPrecision: uint32, # DWORD
iClipPrecision: uint32, # DWORD
iQuality: uint32, # DWORD
iPitchAndFamily: uint32, # DWORD
pszFaceName: cstring # LPCSTR optional
): pointer {.importc: "CreateFontA", stdcall, dynlib: "GDI32.dll".}pragma(lib, "gdi32");
extern(Windows)
void* 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
const(char)* pszFaceName // LPCSTR optional
);ccall((:CreateFontA, "GDI32.dll"), stdcall, Ptr{Cvoid},
(Int32, Int32, Int32, Int32, Int32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, Cstring),
cHeight, cWidth, cEscapement, cOrientation, cWeight, bItalic, bUnderline, bStrikeOut, iCharSet, iOutPrecision, iClipPrecision, iQuality, iPitchAndFamily, pszFaceName)
# cHeight : INT -> Int32
# cWidth : INT -> Int32
# cEscapement : INT -> Int32
# cOrientation : INT -> Int32
# cWeight : INT -> Int32
# bItalic : DWORD -> UInt32
# bUnderline : DWORD -> UInt32
# bStrikeOut : DWORD -> UInt32
# iCharSet : DWORD -> UInt32
# iOutPrecision : DWORD -> UInt32
# iClipPrecision : DWORD -> UInt32
# iQuality : DWORD -> UInt32
# iPitchAndFamily : DWORD -> UInt32
# pszFaceName : LPCSTR optional -> Cstring
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
void* CreateFontA(
int32_t cHeight,
int32_t cWidth,
int32_t cEscapement,
int32_t cOrientation,
int32_t cWeight,
uint32_t bItalic,
uint32_t bUnderline,
uint32_t bStrikeOut,
uint32_t iCharSet,
uint32_t iOutPrecision,
uint32_t iClipPrecision,
uint32_t iQuality,
uint32_t iPitchAndFamily,
const char* pszFaceName);
]]
local gdi32 = ffi.load("gdi32")
-- gdi32.CreateFontA(cHeight, cWidth, cEscapement, cOrientation, cWeight, bItalic, bUnderline, bStrikeOut, iCharSet, iOutPrecision, iClipPrecision, iQuality, iPitchAndFamily, pszFaceName)
-- 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
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('GDI32.dll');
const CreateFontA = lib.func('__stdcall', 'CreateFontA', 'void *', ['int32_t', 'int32_t', 'int32_t', 'int32_t', 'int32_t', 'uint32_t', 'uint32_t', 'uint32_t', 'uint32_t', 'uint32_t', 'uint32_t', 'uint32_t', 'uint32_t', 'str']);
// CreateFontA(cHeight, cWidth, cEscapement, cOrientation, cWeight, bItalic, bUnderline, bStrikeOut, iCharSet, iOutPrecision, iClipPrecision, iQuality, iPitchAndFamily, pszFaceName)
// cHeight : INT -> 'int32_t'
// cWidth : INT -> 'int32_t'
// cEscapement : INT -> 'int32_t'
// cOrientation : INT -> 'int32_t'
// cWeight : INT -> 'int32_t'
// bItalic : DWORD -> 'uint32_t'
// bUnderline : DWORD -> 'uint32_t'
// bStrikeOut : DWORD -> 'uint32_t'
// iCharSet : DWORD -> 'uint32_t'
// iOutPrecision : DWORD -> 'uint32_t'
// iClipPrecision : DWORD -> 'uint32_t'
// iQuality : DWORD -> 'uint32_t'
// iPitchAndFamily : DWORD -> 'uint32_t'
// pszFaceName : LPCSTR optional -> 'str'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("GDI32.dll", {
CreateFontA: { parameters: ["i32", "i32", "i32", "i32", "i32", "u32", "u32", "u32", "u32", "u32", "u32", "u32", "u32", "buffer"], result: "pointer" },
});
// lib.symbols.CreateFontA(cHeight, cWidth, cEscapement, cOrientation, cWeight, bItalic, bUnderline, bStrikeOut, iCharSet, iOutPrecision, iClipPrecision, iQuality, iPitchAndFamily, pszFaceName)
// cHeight : INT -> "i32"
// cWidth : INT -> "i32"
// cEscapement : INT -> "i32"
// cOrientation : INT -> "i32"
// cWeight : INT -> "i32"
// bItalic : DWORD -> "u32"
// bUnderline : DWORD -> "u32"
// bStrikeOut : DWORD -> "u32"
// iCharSet : DWORD -> "u32"
// iOutPrecision : DWORD -> "u32"
// iClipPrecision : DWORD -> "u32"
// iQuality : DWORD -> "u32"
// iPitchAndFamily : DWORD -> "u32"
// pszFaceName : LPCSTR optional -> "buffer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
void* CreateFontA(
int32_t cHeight,
int32_t cWidth,
int32_t cEscapement,
int32_t cOrientation,
int32_t cWeight,
uint32_t bItalic,
uint32_t bUnderline,
uint32_t bStrikeOut,
uint32_t iCharSet,
uint32_t iOutPrecision,
uint32_t iClipPrecision,
uint32_t iQuality,
uint32_t iPitchAndFamily,
const char* pszFaceName);
C, "GDI32.dll");
// $ffi->CreateFontA(cHeight, cWidth, cEscapement, cOrientation, cWeight, bItalic, bUnderline, bStrikeOut, iCharSet, iOutPrecision, iClipPrecision, iQuality, iPitchAndFamily, pszFaceName);
// 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
// 構造体/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);
Pointer CreateFontA(
int 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
String pszFaceName // LPCSTR optional
);
}@[Link("gdi32")]
lib LibGDI32
fun CreateFontA = CreateFontA(
cHeight : Int32, # INT
cWidth : Int32, # INT
cEscapement : Int32, # INT
cOrientation : Int32, # INT
cWeight : Int32, # INT
bItalic : UInt32, # DWORD
bUnderline : UInt32, # DWORD
bStrikeOut : UInt32, # DWORD
iCharSet : UInt32, # DWORD
iOutPrecision : UInt32, # DWORD
iClipPrecision : UInt32, # DWORD
iQuality : UInt32, # DWORD
iPitchAndFamily : UInt32, # DWORD
pszFaceName : UInt8* # LPCSTR optional
) : Void*
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef CreateFontANative = Pointer<Void> Function(Int32, Int32, Int32, Int32, Int32, Uint32, Uint32, Uint32, Uint32, Uint32, Uint32, Uint32, Uint32, Pointer<Utf8>);
typedef CreateFontADart = Pointer<Void> Function(int, int, int, int, int, int, int, int, int, int, int, int, int, Pointer<Utf8>);
final CreateFontA = DynamicLibrary.open('GDI32.dll')
.lookupFunction<CreateFontANative, CreateFontADart>('CreateFontA');
// cHeight : INT -> Int32
// cWidth : INT -> Int32
// cEscapement : INT -> Int32
// cOrientation : INT -> Int32
// cWeight : INT -> Int32
// bItalic : DWORD -> Uint32
// bUnderline : DWORD -> Uint32
// bStrikeOut : DWORD -> Uint32
// iCharSet : DWORD -> Uint32
// iOutPrecision : DWORD -> Uint32
// iClipPrecision : DWORD -> Uint32
// iQuality : DWORD -> Uint32
// iPitchAndFamily : DWORD -> Uint32
// pszFaceName : LPCSTR optional -> Pointer<Utf8>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
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';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "CreateFontA"
c_CreateFontA :: Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> Word32 -> Word32 -> Word32 -> Word32 -> Word32 -> Word32 -> Word32 -> Word32 -> CString -> IO (Ptr ())
-- cHeight : INT -> Int32
-- cWidth : INT -> Int32
-- cEscapement : INT -> Int32
-- cOrientation : INT -> Int32
-- cWeight : INT -> Int32
-- bItalic : DWORD -> Word32
-- bUnderline : DWORD -> Word32
-- bStrikeOut : DWORD -> Word32
-- iCharSet : DWORD -> Word32
-- iOutPrecision : DWORD -> Word32
-- iClipPrecision : DWORD -> Word32
-- iQuality : DWORD -> Word32
-- iPitchAndFamily : DWORD -> Word32
-- pszFaceName : LPCSTR optional -> CString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let createfonta =
foreign "CreateFontA"
(int32_t @-> int32_t @-> int32_t @-> int32_t @-> int32_t @-> uint32_t @-> uint32_t @-> uint32_t @-> uint32_t @-> uint32_t @-> uint32_t @-> uint32_t @-> uint32_t @-> string @-> returning (ptr void))
(* cHeight : INT -> int32_t *)
(* cWidth : INT -> int32_t *)
(* cEscapement : INT -> int32_t *)
(* cOrientation : INT -> int32_t *)
(* cWeight : INT -> int32_t *)
(* bItalic : DWORD -> uint32_t *)
(* bUnderline : DWORD -> uint32_t *)
(* bStrikeOut : DWORD -> uint32_t *)
(* iCharSet : DWORD -> uint32_t *)
(* iOutPrecision : DWORD -> uint32_t *)
(* iClipPrecision : DWORD -> uint32_t *)
(* iQuality : DWORD -> uint32_t *)
(* iPitchAndFamily : DWORD -> uint32_t *)
(* pszFaceName : LPCSTR optional -> string *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library gdi32 (t "GDI32.dll"))
(cffi:use-foreign-library gdi32)
(cffi:defcfun ("CreateFontA" create-font-a :convention :stdcall) :pointer
(c-height :int32) ; INT
(c-width :int32) ; INT
(c-escapement :int32) ; INT
(c-orientation :int32) ; INT
(c-weight :int32) ; INT
(b-italic :uint32) ; DWORD
(b-underline :uint32) ; DWORD
(b-strike-out :uint32) ; DWORD
(i-char-set :uint32) ; DWORD
(i-out-precision :uint32) ; DWORD
(i-clip-precision :uint32) ; DWORD
(i-quality :uint32) ; DWORD
(i-pitch-and-family :uint32) ; DWORD
(psz-face-name :string)) ; LPCSTR optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $CreateFontA = Win32::API::More->new('GDI32',
'HANDLE 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)');
# my $ret = $CreateFontA->Call($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 -> LPCSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
- f CreateFontW (Unicode版) — 高さや太さなど多数の属性を指定して論理フォントを作成する。
- f CreateFontIndirectA — LOGFONT構造体の指定に基づき論理フォントを作成する(ANSI版)。
- f CreateFontIndirectExA — 拡張論理フォント情報からフォントを作成する。
- f DeleteObject — 指定したGDIオブジェクトを削除しリソースを解放する。
- f EnumFontFamiliesExA — 条件に一致するフォントを列挙しコールバックに渡す。
- f EnumFontsA — デバイスで利用可能なフォントを列挙する。
- s LOGFONTA
- f SelectObject — デバイスコンテキストにGDIオブジェクトを選択し、同種の前のオブジェクトを返す。