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

SetConsoleTitleA

関数
コンソールウィンドウのタイトル文字列を設定する(ANSI版)。
DLLKERNEL32.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり

シグネチャ

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

BOOL SetConsoleTitleA(
    LPCSTR lpConsoleTitle
);

パラメーター

名前方向
lpConsoleTitleLPCSTRin

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL SetConsoleTitleA(
    LPCSTR lpConsoleTitle
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool SetConsoleTitleA(
    [MarshalAs(UnmanagedType.LPStr)] string lpConsoleTitle   // LPCSTR
);
<DllImport("KERNEL32.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetConsoleTitleA(
    <MarshalAs(UnmanagedType.LPStr)> lpConsoleTitle As String   ' LPCSTR
) As Boolean
End Function
' lpConsoleTitle : LPCSTR
Declare PtrSafe Function SetConsoleTitleA Lib "kernel32" ( _
    ByVal lpConsoleTitle As String) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SetConsoleTitleA = ctypes.windll.kernel32.SetConsoleTitleA
SetConsoleTitleA.restype = wintypes.BOOL
SetConsoleTitleA.argtypes = [
    wintypes.LPCSTR,  # lpConsoleTitle : LPCSTR
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
SetConsoleTitleA = Fiddle::Function.new(
  lib['SetConsoleTitleA'],
  [
    Fiddle::TYPE_VOIDP,  # lpConsoleTitle : LPCSTR
  ],
  Fiddle::TYPE_INT)
#[link(name = "kernel32")]
extern "system" {
    fn SetConsoleTitleA(
        lpConsoleTitle: *const u8  // LPCSTR
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern bool SetConsoleTitleA([MarshalAs(UnmanagedType.LPStr)] string lpConsoleTitle);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_SetConsoleTitleA' -Namespace Win32 -PassThru
# $api::SetConsoleTitleA(lpConsoleTitle)
#uselib "KERNEL32.dll"
#func global SetConsoleTitleA "SetConsoleTitleA" sptr
; SetConsoleTitleA lpConsoleTitle   ; 戻り値は stat
; lpConsoleTitle : LPCSTR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "KERNEL32.dll"
#cfunc global SetConsoleTitleA "SetConsoleTitleA" str
; res = SetConsoleTitleA(lpConsoleTitle)
; lpConsoleTitle : LPCSTR -> "str"
; BOOL SetConsoleTitleA(LPCSTR lpConsoleTitle)
#uselib "KERNEL32.dll"
#cfunc global SetConsoleTitleA "SetConsoleTitleA" str
; res = SetConsoleTitleA(lpConsoleTitle)
; lpConsoleTitle : LPCSTR -> "str"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procSetConsoleTitleA = kernel32.NewProc("SetConsoleTitleA")
)

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