Win32 API 日本語リファレンス
ホームSystem.Console › SetCurrentConsoleFontEx

SetCurrentConsoleFontEx

関数
コンソールで使用するフォントの拡張情報を設定する。
DLLKERNEL32.dll呼出規約winapiSetLastErrorあり

シグネチャ

// KERNEL32.dll
#include <windows.h>

BOOL SetCurrentConsoleFontEx(
    HANDLE hConsoleOutput,
    BOOL bMaximumWindow,
    CONSOLE_FONT_INFOEX* lpConsoleCurrentFontEx
);

パラメーター

名前方向
hConsoleOutputHANDLEin
bMaximumWindowBOOLin
lpConsoleCurrentFontExCONSOLE_FONT_INFOEX*in

戻り値の型: BOOL

各言語での呼び出し定義

// KERNEL32.dll
#include <windows.h>

BOOL SetCurrentConsoleFontEx(
    HANDLE hConsoleOutput,
    BOOL bMaximumWindow,
    CONSOLE_FONT_INFOEX* lpConsoleCurrentFontEx
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool SetCurrentConsoleFontEx(
    IntPtr hConsoleOutput,   // HANDLE
    bool bMaximumWindow,   // BOOL
    IntPtr lpConsoleCurrentFontEx   // CONSOLE_FONT_INFOEX*
);
<DllImport("KERNEL32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetCurrentConsoleFontEx(
    hConsoleOutput As IntPtr,   ' HANDLE
    bMaximumWindow As Boolean,   ' BOOL
    lpConsoleCurrentFontEx As IntPtr   ' CONSOLE_FONT_INFOEX*
) As Boolean
End Function
' hConsoleOutput : HANDLE
' bMaximumWindow : BOOL
' lpConsoleCurrentFontEx : CONSOLE_FONT_INFOEX*
Declare PtrSafe Function SetCurrentConsoleFontEx Lib "kernel32" ( _
    ByVal hConsoleOutput As LongPtr, _
    ByVal bMaximumWindow As Long, _
    ByVal lpConsoleCurrentFontEx As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SetCurrentConsoleFontEx = ctypes.windll.kernel32.SetCurrentConsoleFontEx
SetCurrentConsoleFontEx.restype = wintypes.BOOL
SetCurrentConsoleFontEx.argtypes = [
    wintypes.HANDLE,  # hConsoleOutput : HANDLE
    wintypes.BOOL,  # bMaximumWindow : BOOL
    ctypes.c_void_p,  # lpConsoleCurrentFontEx : CONSOLE_FONT_INFOEX*
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
SetCurrentConsoleFontEx = Fiddle::Function.new(
  lib['SetCurrentConsoleFontEx'],
  [
    Fiddle::TYPE_VOIDP,  # hConsoleOutput : HANDLE
    Fiddle::TYPE_INT,  # bMaximumWindow : BOOL
    Fiddle::TYPE_VOIDP,  # lpConsoleCurrentFontEx : CONSOLE_FONT_INFOEX*
  ],
  Fiddle::TYPE_INT)
#[link(name = "kernel32")]
extern "system" {
    fn SetCurrentConsoleFontEx(
        hConsoleOutput: *mut core::ffi::c_void,  // HANDLE
        bMaximumWindow: i32,  // BOOL
        lpConsoleCurrentFontEx: *mut CONSOLE_FONT_INFOEX  // CONSOLE_FONT_INFOEX*
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", SetLastError = true)]
public static extern bool SetCurrentConsoleFontEx(IntPtr hConsoleOutput, bool bMaximumWindow, IntPtr lpConsoleCurrentFontEx);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_SetCurrentConsoleFontEx' -Namespace Win32 -PassThru
# $api::SetCurrentConsoleFontEx(hConsoleOutput, bMaximumWindow, lpConsoleCurrentFontEx)
#uselib "KERNEL32.dll"
#func global SetCurrentConsoleFontEx "SetCurrentConsoleFontEx" sptr, sptr, sptr
; SetCurrentConsoleFontEx hConsoleOutput, bMaximumWindow, varptr(lpConsoleCurrentFontEx)   ; 戻り値は stat
; hConsoleOutput : HANDLE -> "sptr"
; bMaximumWindow : BOOL -> "sptr"
; lpConsoleCurrentFontEx : CONSOLE_FONT_INFOEX* -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "KERNEL32.dll"
#cfunc global SetCurrentConsoleFontEx "SetCurrentConsoleFontEx" sptr, int, var
; res = SetCurrentConsoleFontEx(hConsoleOutput, bMaximumWindow, lpConsoleCurrentFontEx)
; hConsoleOutput : HANDLE -> "sptr"
; bMaximumWindow : BOOL -> "int"
; lpConsoleCurrentFontEx : CONSOLE_FONT_INFOEX* -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL SetCurrentConsoleFontEx(HANDLE hConsoleOutput, BOOL bMaximumWindow, CONSOLE_FONT_INFOEX* lpConsoleCurrentFontEx)
#uselib "KERNEL32.dll"
#cfunc global SetCurrentConsoleFontEx "SetCurrentConsoleFontEx" intptr, int, var
; res = SetCurrentConsoleFontEx(hConsoleOutput, bMaximumWindow, lpConsoleCurrentFontEx)
; hConsoleOutput : HANDLE -> "intptr"
; bMaximumWindow : BOOL -> "int"
; lpConsoleCurrentFontEx : CONSOLE_FONT_INFOEX* -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procSetCurrentConsoleFontEx = kernel32.NewProc("SetCurrentConsoleFontEx")
)

// hConsoleOutput (HANDLE), bMaximumWindow (BOOL), lpConsoleCurrentFontEx (CONSOLE_FONT_INFOEX*)
r1, _, err := procSetCurrentConsoleFontEx.Call(
	uintptr(hConsoleOutput),
	uintptr(bMaximumWindow),
	uintptr(lpConsoleCurrentFontEx),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function SetCurrentConsoleFontEx(
  hConsoleOutput: THandle;   // HANDLE
  bMaximumWindow: BOOL;   // BOOL
  lpConsoleCurrentFontEx: Pointer   // CONSOLE_FONT_INFOEX*
): BOOL; stdcall;
  external 'KERNEL32.dll' name 'SetCurrentConsoleFontEx';
result := DllCall("KERNEL32\SetCurrentConsoleFontEx"
    , "Ptr", hConsoleOutput   ; HANDLE
    , "Int", bMaximumWindow   ; BOOL
    , "Ptr", lpConsoleCurrentFontEx   ; CONSOLE_FONT_INFOEX*
    , "Int")   ; return: BOOL
●SetCurrentConsoleFontEx(hConsoleOutput, bMaximumWindow, lpConsoleCurrentFontEx) = DLL("KERNEL32.dll", "bool SetCurrentConsoleFontEx(void*, bool, void*)")
# 呼び出し: SetCurrentConsoleFontEx(hConsoleOutput, bMaximumWindow, lpConsoleCurrentFontEx)
# hConsoleOutput : HANDLE -> "void*"
# bMaximumWindow : BOOL -> "bool"
# lpConsoleCurrentFontEx : CONSOLE_FONT_INFOEX* -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。