ホーム › System.Console › CONSOLE_SCREEN_BUFFER_INFO
CONSOLE_SCREEN_BUFFER_INFO
構造体サイズ=各フィールドのバイト数(x64/x86 で異なる場合は x64/x86 と併記)。x64/x86 列=フィールドのバイトオフセット(HSPで dupptr / lpoke / wpoke 等に使用)。
フィールド
| フィールド | 型 | サイズ | x64 | x86 | 説明 |
|---|---|---|---|---|---|
| dwSize | COORD | 4 | +0 | +0 | スクリーンバッファのサイズ(列数×行数、COORD)。 |
| dwCursorPosition | COORD | 4 | +4 | +4 | 現在のカーソル位置(COORD)。 |
| wAttributes | CONSOLE_CHARACTER_ATTRIBUTES | 2 | +8 | +8 | 現在の文字色属性(CONSOLE_CHARACTER_ATTRIBUTES)。 |
| srWindow | SMALL_RECT | 8 | +10 | +10 | 表示中のウィンドウ領域を示す矩形(SMALL_RECT)。 |
| dwMaximumWindowSize | COORD | 4 | +18 | +18 | 現在のフォントとディスプレイで可能な最大ウィンドウサイズ(COORD)。 |
各言語での定義
#include <windows.h>
// COORD (x64 4 / x86 4 バイト)
typedef struct COORD {
SHORT X;
SHORT Y;
} COORD;
// SMALL_RECT (x64 8 / x86 8 バイト)
typedef struct SMALL_RECT {
SHORT Left;
SHORT Top;
SHORT Right;
SHORT Bottom;
} SMALL_RECT;
// CONSOLE_SCREEN_BUFFER_INFO (x64 22 / x86 22 バイト)
typedef struct CONSOLE_SCREEN_BUFFER_INFO {
COORD dwSize;
COORD dwCursorPosition;
CONSOLE_CHARACTER_ATTRIBUTES wAttributes;
SMALL_RECT srWindow;
COORD dwMaximumWindowSize;
} CONSOLE_SCREEN_BUFFER_INFO;using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct COORD
{
public short X;
public short Y;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct SMALL_RECT
{
public short Left;
public short Top;
public short Right;
public short Bottom;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct CONSOLE_SCREEN_BUFFER_INFO
{
public COORD dwSize;
public COORD dwCursorPosition;
public ushort wAttributes;
public SMALL_RECT srWindow;
public COORD dwMaximumWindowSize;
}Imports System.Runtime.InteropServices
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure COORD
Public X As Short
Public Y As Short
End Structure
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure SMALL_RECT
Public Left As Short
Public Top As Short
Public Right As Short
Public Bottom As Short
End Structure
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure CONSOLE_SCREEN_BUFFER_INFO
Public dwSize As COORD
Public dwCursorPosition As COORD
Public wAttributes As UShort
Public srWindow As SMALL_RECT
Public dwMaximumWindowSize As COORD
End Structureimport ctypes
from ctypes import wintypes
class COORD(ctypes.Structure):
_fields_ = [
("X", ctypes.c_short),
("Y", ctypes.c_short),
]
class SMALL_RECT(ctypes.Structure):
_fields_ = [
("Left", ctypes.c_short),
("Top", ctypes.c_short),
("Right", ctypes.c_short),
("Bottom", ctypes.c_short),
]
class CONSOLE_SCREEN_BUFFER_INFO(ctypes.Structure):
_fields_ = [
("dwSize", COORD),
("dwCursorPosition", COORD),
("wAttributes", ctypes.c_ushort),
("srWindow", SMALL_RECT),
("dwMaximumWindowSize", COORD),
]#[repr(C)]
pub struct COORD {
pub X: i16,
pub Y: i16,
}
#[repr(C)]
pub struct SMALL_RECT {
pub Left: i16,
pub Top: i16,
pub Right: i16,
pub Bottom: i16,
}
#[repr(C)]
pub struct CONSOLE_SCREEN_BUFFER_INFO {
pub dwSize: COORD,
pub dwCursorPosition: COORD,
pub wAttributes: u16,
pub srWindow: SMALL_RECT,
pub dwMaximumWindowSize: COORD,
}import "golang.org/x/sys/windows"
type COORD struct {
X int16
Y int16
}
type SMALL_RECT struct {
Left int16
Top int16
Right int16
Bottom int16
}
type CONSOLE_SCREEN_BUFFER_INFO struct {
dwSize COORD
dwCursorPosition COORD
wAttributes uint16
srWindow SMALL_RECT
dwMaximumWindowSize COORD
}type
COORD = record
X: Smallint;
Y: Smallint;
end;
SMALL_RECT = record
Left: Smallint;
Top: Smallint;
Right: Smallint;
Bottom: Smallint;
end;
CONSOLE_SCREEN_BUFFER_INFO = record
dwSize: COORD;
dwCursorPosition: COORD;
wAttributes: Word;
srWindow: SMALL_RECT;
dwMaximumWindowSize: COORD;
end;const COORD = extern struct {
X: i16,
Y: i16,
};
const SMALL_RECT = extern struct {
Left: i16,
Top: i16,
Right: i16,
Bottom: i16,
};
const CONSOLE_SCREEN_BUFFER_INFO = extern struct {
dwSize: COORD,
dwCursorPosition: COORD,
wAttributes: u16,
srWindow: SMALL_RECT,
dwMaximumWindowSize: COORD,
};type
COORD {.bycopy.} = object
X: int16
Y: int16
SMALL_RECT {.bycopy.} = object
Left: int16
Top: int16
Right: int16
Bottom: int16
CONSOLE_SCREEN_BUFFER_INFO {.bycopy.} = object
dwSize: COORD
dwCursorPosition: COORD
wAttributes: uint16
srWindow: SMALL_RECT
dwMaximumWindowSize: COORDstruct COORD
{
short X;
short Y;
}
struct SMALL_RECT
{
short Left;
short Top;
short Right;
short Bottom;
}
struct CONSOLE_SCREEN_BUFFER_INFO
{
COORD dwSize;
COORD dwCursorPosition;
ushort wAttributes;
SMALL_RECT srWindow;
COORD dwMaximumWindowSize;
}HSP用 定義
HSP3.7/3.8 は構造体機能が無いため4byte整数配列(dim)+peek/poke で操作(32/64bitでサイズ・位置が異なる場合はタブで分割)。IronHSP は NSTRUCT(#defstruct/stdim/->)で32/64bit共通。
; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; CONSOLE_SCREEN_BUFFER_INFO サイズ: 22 バイト(x64)
dim st, 6 ; 4byte整数×6(構造体サイズ 22 / 4 切り上げ)
; dwSize : COORD (+0, 4byte) varptr(st)+0 を基点に操作(4byte:入れ子/配列)
; dwCursorPosition : COORD (+4, 4byte) varptr(st)+4 を基点に操作(4byte:入れ子/配列)
; wAttributes : CONSOLE_CHARACTER_ATTRIBUTES (+8, 2byte) wpoke st,8,値 / 値 = wpeek(st,8)
; srWindow : SMALL_RECT (+10, 8byte) varptr(st)+10 を基点に操作(8byte:入れ子/配列)
; dwMaximumWindowSize : COORD (+18, 4byte) varptr(st)+18 を基点に操作(4byte:入れ子/配列)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
; ※GUID・入れ子構造体はデフォルト型でないため、依存する #defstruct を先に定義(下記に同梱)。
#defstruct global COORD
#field short X
#field short Y
#endstruct
#defstruct global SMALL_RECT
#field short Left
#field short Top
#field short Right
#field short Bottom
#endstruct
#defstruct global CONSOLE_SCREEN_BUFFER_INFO
#field COORD dwSize
#field COORD dwCursorPosition
#field short wAttributes
#field SMALL_RECT srWindow
#field COORD dwMaximumWindowSize
#endstruct
stdim st, CONSOLE_SCREEN_BUFFER_INFO ; NSTRUCT 変数を確保
st->wAttributes = 100
mes "wAttributes=" + st->wAttributes