ホーム › System.Console › SetConsoleTitleW
SetConsoleTitleW
関数コンソールウィンドウのタイトル文字列を設定する(Unicode版)。
シグネチャ
// KERNEL32.dll (Unicode / -W)
#include <windows.h>
BOOL SetConsoleTitleW(
LPCWSTR lpConsoleTitle
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| lpConsoleTitle | LPCWSTR | in |
戻り値の型: BOOL
各言語での呼び出し定義
// KERNEL32.dll (Unicode / -W)
#include <windows.h>
BOOL SetConsoleTitleW(
LPCWSTR lpConsoleTitle
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool SetConsoleTitleW(
[MarshalAs(UnmanagedType.LPWStr)] string lpConsoleTitle // LPCWSTR
);<DllImport("KERNEL32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetConsoleTitleW(
<MarshalAs(UnmanagedType.LPWStr)> lpConsoleTitle As String ' LPCWSTR
) As Boolean
End Function' lpConsoleTitle : LPCWSTR
Declare PtrSafe Function SetConsoleTitleW Lib "kernel32" ( _
ByVal lpConsoleTitle As LongPtr) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SetConsoleTitleW = ctypes.windll.kernel32.SetConsoleTitleW
SetConsoleTitleW.restype = wintypes.BOOL
SetConsoleTitleW.argtypes = [
wintypes.LPCWSTR, # lpConsoleTitle : LPCWSTR
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
SetConsoleTitleW = Fiddle::Function.new(
lib['SetConsoleTitleW'],
[
Fiddle::TYPE_VOIDP, # lpConsoleTitle : LPCWSTR
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "kernel32")]
extern "system" {
fn SetConsoleTitleW(
lpConsoleTitle: *const u16 // LPCWSTR
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern bool SetConsoleTitleW([MarshalAs(UnmanagedType.LPWStr)] string lpConsoleTitle);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_SetConsoleTitleW' -Namespace Win32 -PassThru
# $api::SetConsoleTitleW(lpConsoleTitle)#uselib "KERNEL32.dll"
#func global SetConsoleTitleW "SetConsoleTitleW" wptr
; SetConsoleTitleW lpConsoleTitle ; 戻り値は stat
; lpConsoleTitle : LPCWSTR -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "KERNEL32.dll"
#cfunc global SetConsoleTitleW "SetConsoleTitleW" wstr
; res = SetConsoleTitleW(lpConsoleTitle)
; lpConsoleTitle : LPCWSTR -> "wstr"; BOOL SetConsoleTitleW(LPCWSTR lpConsoleTitle)
#uselib "KERNEL32.dll"
#cfunc global SetConsoleTitleW "SetConsoleTitleW" wstr
; res = SetConsoleTitleW(lpConsoleTitle)
; lpConsoleTitle : LPCWSTR -> "wstr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procSetConsoleTitleW = kernel32.NewProc("SetConsoleTitleW")
)
// lpConsoleTitle (LPCWSTR)
r1, _, err := procSetConsoleTitleW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpConsoleTitle))),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction SetConsoleTitleW(
lpConsoleTitle: PWideChar // LPCWSTR
): BOOL; stdcall;
external 'KERNEL32.dll' name 'SetConsoleTitleW';result := DllCall("KERNEL32\SetConsoleTitleW"
, "WStr", lpConsoleTitle ; LPCWSTR
, "Int") ; return: BOOL●SetConsoleTitleW(lpConsoleTitle) = DLL("KERNEL32.dll", "bool SetConsoleTitleW(char*)")
# 呼び出し: SetConsoleTitleW(lpConsoleTitle)
# lpConsoleTitle : LPCWSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。