Win32 API 日本語リファレンス
ホームUI.Controls.RichEdit › CHARFORMAT2W

CHARFORMAT2W

構造体
サイズx64: 116 バイト / x86: 116 バイト

サイズ=各フィールドのバイト数(x64/x86 で異なる場合は x64/x86 と併記)。x64/x86 列=フィールドのバイトオフセット(HSPで dupptr / lpoke / wpoke 等に使用)。

フィールド

フィールドサイズx64x86
BaseCHARFORMATW92+0+0
wWeightWORD2+92+92
sSpacingSHORT2+94+94
crBackColorCOLORREF4+96+96
lcidDWORD4+100+100
Anonymous_Anonymous_e__Union4+104+104
sStyleSHORT2+108+108
wKerningWORD2+110+110
bUnderlineTypeBYTE1+112+112
bAnimationBYTE1+113+113
bRevAuthorBYTE1+114+114
bUnderlineColorBYTE1+115+115

共用体: _Anonymous_e__Union x64 4B / x86 4B

フィールドサイズx64x86
dwReservedDWORD4+0+0
dwCookieDWORD4+0+0

各言語での定義

#include <windows.h>

// CHARFORMATW  (x64 92 / x86 92 バイト)
typedef struct CHARFORMATW {
    DWORD cbSize;
    CFM_MASK dwMask;
    CFE_EFFECTS dwEffects;
    INT yHeight;
    INT yOffset;
    COLORREF crTextColor;
    FONT_CHARSET bCharSet;
    BYTE bPitchAndFamily;
    WCHAR szFaceName[32];
} CHARFORMATW;

// CHARFORMAT2W  (x64 116 / x86 116 バイト)
typedef struct CHARFORMAT2W {
    CHARFORMATW Base;
    WORD wWeight;
    SHORT sSpacing;
    COLORREF crBackColor;
    DWORD lcid;
    _Anonymous_e__Union Anonymous;
    SHORT sStyle;
    WORD wKerning;
    BYTE bUnderlineType;
    BYTE bAnimation;
    BYTE bRevAuthor;
    BYTE bUnderlineColor;
} CHARFORMAT2W;
using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct CHARFORMATW
{
    public uint cbSize;
    public uint dwMask;
    public uint dwEffects;
    public int yHeight;
    public int yOffset;
    public uint crTextColor;
    public byte bCharSet;
    public byte bPitchAndFamily;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] public string szFaceName;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct CHARFORMAT2W
{
    public CHARFORMATW Base;
    public ushort wWeight;
    public short sSpacing;
    public uint crBackColor;
    public uint lcid;
    public _Anonymous_e__Union Anonymous;
    public short sStyle;
    public ushort wKerning;
    public byte bUnderlineType;
    public byte bAnimation;
    public byte bRevAuthor;
    public byte bUnderlineColor;
}
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure CHARFORMATW
    Public cbSize As UInteger
    Public dwMask As UInteger
    Public dwEffects As UInteger
    Public yHeight As Integer
    Public yOffset As Integer
    Public crTextColor As UInteger
    Public bCharSet As Byte
    Public bPitchAndFamily As Byte
    <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=32)> Public szFaceName As String
End Structure

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure CHARFORMAT2W
    Public Base As CHARFORMATW
    Public wWeight As UShort
    Public sSpacing As Short
    Public crBackColor As UInteger
    Public lcid As UInteger
    Public Anonymous As _Anonymous_e__Union
    Public sStyle As Short
    Public wKerning As UShort
    Public bUnderlineType As Byte
    Public bAnimation As Byte
    Public bRevAuthor As Byte
    Public bUnderlineColor As Byte
End Structure
import ctypes
from ctypes import wintypes

class CHARFORMATW(ctypes.Structure):
    _fields_ = [
        ("cbSize", wintypes.DWORD),
        ("dwMask", wintypes.DWORD),
        ("dwEffects", wintypes.DWORD),
        ("yHeight", ctypes.c_int),
        ("yOffset", ctypes.c_int),
        ("crTextColor", wintypes.DWORD),
        ("bCharSet", ctypes.c_ubyte),
        ("bPitchAndFamily", ctypes.c_ubyte),
        ("szFaceName", ctypes.c_wchar * 32),
    ]

class CHARFORMAT2W(ctypes.Structure):
    _fields_ = [
        ("Base", CHARFORMATW),
        ("wWeight", ctypes.c_ushort),
        ("sSpacing", ctypes.c_short),
        ("crBackColor", wintypes.DWORD),
        ("lcid", wintypes.DWORD),
        ("Anonymous", _Anonymous_e__Union),
        ("sStyle", ctypes.c_short),
        ("wKerning", ctypes.c_ushort),
        ("bUnderlineType", ctypes.c_ubyte),
        ("bAnimation", ctypes.c_ubyte),
        ("bRevAuthor", ctypes.c_ubyte),
        ("bUnderlineColor", ctypes.c_ubyte),
    ]
#[repr(C)]
pub struct CHARFORMATW {
    pub cbSize: u32,
    pub dwMask: u32,
    pub dwEffects: u32,
    pub yHeight: i32,
    pub yOffset: i32,
    pub crTextColor: u32,
    pub bCharSet: u8,
    pub bPitchAndFamily: u8,
    pub szFaceName: [u16; 32],
}

#[repr(C)]
pub struct CHARFORMAT2W {
    pub Base: CHARFORMATW,
    pub wWeight: u16,
    pub sSpacing: i16,
    pub crBackColor: u32,
    pub lcid: u32,
    pub Anonymous: _Anonymous_e__Union,
    pub sStyle: i16,
    pub wKerning: u16,
    pub bUnderlineType: u8,
    pub bAnimation: u8,
    pub bRevAuthor: u8,
    pub bUnderlineColor: u8,
}
import "golang.org/x/sys/windows"

type CHARFORMATW struct {
	cbSize uint32
	dwMask uint32
	dwEffects uint32
	yHeight int32
	yOffset int32
	crTextColor uint32
	bCharSet byte
	bPitchAndFamily byte
	szFaceName [32]uint16
}

type CHARFORMAT2W struct {
	Base CHARFORMATW
	wWeight uint16
	sSpacing int16
	crBackColor uint32
	lcid uint32
	Anonymous _Anonymous_e__Union
	sStyle int16
	wKerning uint16
	bUnderlineType byte
	bAnimation byte
	bRevAuthor byte
	bUnderlineColor byte
}
type
  CHARFORMATW = record
    cbSize: DWORD;
    dwMask: DWORD;
    dwEffects: DWORD;
    yHeight: Integer;
    yOffset: Integer;
    crTextColor: DWORD;
    bCharSet: Byte;
    bPitchAndFamily: Byte;
    szFaceName: array[0..31] of WideChar;
  end;

  CHARFORMAT2W = record
    Base: CHARFORMATW;
    wWeight: Word;
    sSpacing: Smallint;
    crBackColor: DWORD;
    lcid: DWORD;
    Anonymous: _Anonymous_e__Union;
    sStyle: Smallint;
    wKerning: Word;
    bUnderlineType: Byte;
    bAnimation: Byte;
    bRevAuthor: Byte;
    bUnderlineColor: Byte;
  end;
const CHARFORMATW = extern struct {
    cbSize: u32,
    dwMask: u32,
    dwEffects: u32,
    yHeight: i32,
    yOffset: i32,
    crTextColor: u32,
    bCharSet: u8,
    bPitchAndFamily: u8,
    szFaceName: [32]u16,
};

const CHARFORMAT2W = extern struct {
    Base: CHARFORMATW,
    wWeight: u16,
    sSpacing: i16,
    crBackColor: u32,
    lcid: u32,
    Anonymous: _Anonymous_e__Union,
    sStyle: i16,
    wKerning: u16,
    bUnderlineType: u8,
    bAnimation: u8,
    bRevAuthor: u8,
    bUnderlineColor: u8,
};
type
  CHARFORMATW {.bycopy.} = object
    cbSize: uint32
    dwMask: uint32
    dwEffects: uint32
    yHeight: int32
    yOffset: int32
    crTextColor: uint32
    bCharSet: uint8
    bPitchAndFamily: uint8
    szFaceName: array[32, uint16]

  CHARFORMAT2W {.bycopy.} = object
    Base: CHARFORMATW
    wWeight: uint16
    sSpacing: int16
    crBackColor: uint32
    lcid: uint32
    Anonymous: _Anonymous_e__Union
    sStyle: int16
    wKerning: uint16
    bUnderlineType: uint8
    bAnimation: uint8
    bRevAuthor: uint8
    bUnderlineColor: uint8
struct CHARFORMATW
{
    uint cbSize;
    uint dwMask;
    uint dwEffects;
    int yHeight;
    int yOffset;
    uint crTextColor;
    ubyte bCharSet;
    ubyte bPitchAndFamily;
    wchar[32] szFaceName;
}

struct CHARFORMAT2W
{
    CHARFORMATW Base;
    ushort wWeight;
    short sSpacing;
    uint crBackColor;
    uint lcid;
    _Anonymous_e__Union Anonymous;
    short sStyle;
    ushort wKerning;
    ubyte bUnderlineType;
    ubyte bAnimation;
    ubyte bRevAuthor;
    ubyte bUnderlineColor;
}

HSP用 定義

HSP3.7/3.8 は構造体機能が無いため4byte整数配列(dim)+peek/poke で操作(32/64bitでサイズ・位置が異なる場合はタブで分割)。IronHSP は NSTRUCT(#defstruct/stdim/->)で32/64bit共通。

; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; CHARFORMAT2W サイズ: 116 バイト(x64)
dim st, 29    ; 4byte整数×29(構造体サイズ 116 / 4 切り上げ)
; Base : CHARFORMATW (+0, 92byte)  varptr(st)+0 を基点に操作(92byte:入れ子/配列)
; wWeight : WORD (+92, 2byte)  wpoke st,92,値  /  値 = wpeek(st,92)
; sSpacing : SHORT (+94, 2byte)  wpoke st,94,値  /  値 = wpeek(st,94)
; crBackColor : COLORREF (+96, 4byte)  st.24 = 値  /  値 = st.24   (lpoke/lpeek も可)
; lcid : DWORD (+100, 4byte)  st.25 = 値  /  値 = st.25   (lpoke/lpeek も可)
; Anonymous : _Anonymous_e__Union (+104, 4byte)  varptr(st)+104 を基点に操作(4byte:入れ子/配列)
; sStyle : SHORT (+108, 2byte)  wpoke st,108,値  /  値 = wpeek(st,108)
; wKerning : WORD (+110, 2byte)  wpoke st,110,値  /  値 = wpeek(st,110)
; bUnderlineType : BYTE (+112, 1byte)  poke st,112,値  /  値 = peek(st,112)
; bAnimation : BYTE (+113, 1byte)  poke st,113,値  /  値 = peek(st,113)
; bRevAuthor : BYTE (+114, 1byte)  poke st,114,値  /  値 = peek(st,114)
; bUnderlineColor : BYTE (+115, 1byte)  poke st,115,値  /  値 = peek(st,115)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
; ※GUID・入れ子構造体はデフォルト型でないため、依存する #defstruct を先に定義(下記に同梱)。
#defstruct global CHARFORMATW
    #field int cbSize
    #field int dwMask
    #field int dwEffects
    #field int yHeight
    #field int yOffset
    #field int crTextColor
    #field byte bCharSet
    #field byte bPitchAndFamily
    #field wchar szFaceName 32
#endstruct

#defstruct global CHARFORMAT2W
    #field CHARFORMATW Base
    #field short wWeight
    #field short sSpacing
    #field int crBackColor
    #field int lcid
    #field byte Anonymous 4
    #field short sStyle
    #field short wKerning
    #field byte bUnderlineType
    #field byte bAnimation
    #field byte bRevAuthor
    #field byte bUnderlineColor
#endstruct

stdim st, CHARFORMAT2W        ; NSTRUCT 変数を確保
st->wWeight = 100
mes "wWeight=" + st->wWeight
; ※union フィールドは byte 列で確保(NSTRUCT は union 非対応)。必要に応じ手動でアクセス。