Win32 API 日本語リファレンス
ホームDevices.Display › DISPLAYCONFIG_TARGET_PREFERRED_MODE

DISPLAYCONFIG_TARGET_PREFERRED_MODE

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

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

フィールド

フィールドサイズx64x86説明
headerDISPLAYCONFIG_DEVICE_INFO_HEADER20+0+0デバイス情報要求の共通ヘッダ(DISPLAYCONFIG_DEVICE_INFO_HEADER)。
widthDWORD4+20+20ターゲットの推奨表示幅(ピクセル)。
heightDWORD4+24+24ターゲットの推奨表示高さ(ピクセル)。
targetModeDISPLAYCONFIG_TARGET_MODE56/48+32+32推奨される映像信号モード情報(DISPLAYCONFIG_TARGET_MODE)。

各言語での定義

#include <windows.h>

// LUID  (x64 8 / x86 8 バイト)
typedef struct LUID {
    DWORD LowPart;
    INT HighPart;
} LUID;

// DISPLAYCONFIG_DEVICE_INFO_HEADER  (x64 20 / x86 20 バイト)
typedef struct DISPLAYCONFIG_DEVICE_INFO_HEADER {
    DISPLAYCONFIG_DEVICE_INFO_TYPE type;
    DWORD size;
    LUID adapterId;
    DWORD id;
} DISPLAYCONFIG_DEVICE_INFO_HEADER;

// DISPLAYCONFIG_RATIONAL  (x64 8 / x86 8 バイト)
typedef struct DISPLAYCONFIG_RATIONAL {
    DWORD Numerator;
    DWORD Denominator;
} DISPLAYCONFIG_RATIONAL;

// DISPLAYCONFIG_2DREGION  (x64 8 / x86 8 バイト)
typedef struct DISPLAYCONFIG_2DREGION {
    DWORD cx;
    DWORD cy;
} DISPLAYCONFIG_2DREGION;

// DISPLAYCONFIG_VIDEO_SIGNAL_INFO  (x64 56 / x86 48 バイト)
typedef struct DISPLAYCONFIG_VIDEO_SIGNAL_INFO {
    ULONGLONG pixelRate;
    DISPLAYCONFIG_RATIONAL hSyncFreq;
    DISPLAYCONFIG_RATIONAL vSyncFreq;
    DISPLAYCONFIG_2DREGION activeSize;
    DISPLAYCONFIG_2DREGION totalSize;
    _Anonymous_e__Union Anonymous;
    DISPLAYCONFIG_SCANLINE_ORDERING scanLineOrdering;
} DISPLAYCONFIG_VIDEO_SIGNAL_INFO;

// DISPLAYCONFIG_TARGET_MODE  (x64 56 / x86 48 バイト)
typedef struct DISPLAYCONFIG_TARGET_MODE {
    DISPLAYCONFIG_VIDEO_SIGNAL_INFO targetVideoSignalInfo;
} DISPLAYCONFIG_TARGET_MODE;

// DISPLAYCONFIG_TARGET_PREFERRED_MODE  (x64 88 / x86 80 バイト)
typedef struct DISPLAYCONFIG_TARGET_PREFERRED_MODE {
    DISPLAYCONFIG_DEVICE_INFO_HEADER header;
    DWORD width;
    DWORD height;
    DISPLAYCONFIG_TARGET_MODE targetMode;
} DISPLAYCONFIG_TARGET_PREFERRED_MODE;
using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct LUID
{
    public uint LowPart;
    public int HighPart;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct DISPLAYCONFIG_DEVICE_INFO_HEADER
{
    public int type;
    public uint size;
    public LUID adapterId;
    public uint id;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct DISPLAYCONFIG_RATIONAL
{
    public uint Numerator;
    public uint Denominator;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct DISPLAYCONFIG_2DREGION
{
    public uint cx;
    public uint cy;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct DISPLAYCONFIG_VIDEO_SIGNAL_INFO
{
    public ulong pixelRate;
    public DISPLAYCONFIG_RATIONAL hSyncFreq;
    public DISPLAYCONFIG_RATIONAL vSyncFreq;
    public DISPLAYCONFIG_2DREGION activeSize;
    public DISPLAYCONFIG_2DREGION totalSize;
    public _Anonymous_e__Union Anonymous;
    public int scanLineOrdering;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct DISPLAYCONFIG_TARGET_MODE
{
    public DISPLAYCONFIG_VIDEO_SIGNAL_INFO targetVideoSignalInfo;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct DISPLAYCONFIG_TARGET_PREFERRED_MODE
{
    public DISPLAYCONFIG_DEVICE_INFO_HEADER header;
    public uint width;
    public uint height;
    public DISPLAYCONFIG_TARGET_MODE targetMode;
}
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure LUID
    Public LowPart As UInteger
    Public HighPart As Integer
End Structure

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure DISPLAYCONFIG_DEVICE_INFO_HEADER
    Public type As Integer
    Public size As UInteger
    Public adapterId As LUID
    Public id As UInteger
End Structure

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure DISPLAYCONFIG_RATIONAL
    Public Numerator As UInteger
    Public Denominator As UInteger
End Structure

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure DISPLAYCONFIG_2DREGION
    Public cx As UInteger
    Public cy As UInteger
End Structure

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure DISPLAYCONFIG_VIDEO_SIGNAL_INFO
    Public pixelRate As ULong
    Public hSyncFreq As DISPLAYCONFIG_RATIONAL
    Public vSyncFreq As DISPLAYCONFIG_RATIONAL
    Public activeSize As DISPLAYCONFIG_2DREGION
    Public totalSize As DISPLAYCONFIG_2DREGION
    Public Anonymous As _Anonymous_e__Union
    Public scanLineOrdering As Integer
End Structure

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure DISPLAYCONFIG_TARGET_MODE
    Public targetVideoSignalInfo As DISPLAYCONFIG_VIDEO_SIGNAL_INFO
End Structure

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure DISPLAYCONFIG_TARGET_PREFERRED_MODE
    Public header As DISPLAYCONFIG_DEVICE_INFO_HEADER
    Public width As UInteger
    Public height As UInteger
    Public targetMode As DISPLAYCONFIG_TARGET_MODE
End Structure
import ctypes
from ctypes import wintypes

class LUID(ctypes.Structure):
    _fields_ = [
        ("LowPart", wintypes.DWORD),
        ("HighPart", ctypes.c_int),
    ]

class DISPLAYCONFIG_DEVICE_INFO_HEADER(ctypes.Structure):
    _fields_ = [
        ("type", ctypes.c_int),
        ("size", wintypes.DWORD),
        ("adapterId", LUID),
        ("id", wintypes.DWORD),
    ]

class DISPLAYCONFIG_RATIONAL(ctypes.Structure):
    _fields_ = [
        ("Numerator", wintypes.DWORD),
        ("Denominator", wintypes.DWORD),
    ]

class DISPLAYCONFIG_2DREGION(ctypes.Structure):
    _fields_ = [
        ("cx", wintypes.DWORD),
        ("cy", wintypes.DWORD),
    ]

class DISPLAYCONFIG_VIDEO_SIGNAL_INFO(ctypes.Structure):
    _fields_ = [
        ("pixelRate", ctypes.c_ulonglong),
        ("hSyncFreq", DISPLAYCONFIG_RATIONAL),
        ("vSyncFreq", DISPLAYCONFIG_RATIONAL),
        ("activeSize", DISPLAYCONFIG_2DREGION),
        ("totalSize", DISPLAYCONFIG_2DREGION),
        ("Anonymous", _Anonymous_e__Union),
        ("scanLineOrdering", ctypes.c_int),
    ]

class DISPLAYCONFIG_TARGET_MODE(ctypes.Structure):
    _fields_ = [
        ("targetVideoSignalInfo", DISPLAYCONFIG_VIDEO_SIGNAL_INFO),
    ]

class DISPLAYCONFIG_TARGET_PREFERRED_MODE(ctypes.Structure):
    _fields_ = [
        ("header", DISPLAYCONFIG_DEVICE_INFO_HEADER),
        ("width", wintypes.DWORD),
        ("height", wintypes.DWORD),
        ("targetMode", DISPLAYCONFIG_TARGET_MODE),
    ]
#[repr(C)]
pub struct LUID {
    pub LowPart: u32,
    pub HighPart: i32,
}

#[repr(C)]
pub struct DISPLAYCONFIG_DEVICE_INFO_HEADER {
    pub type: i32,
    pub size: u32,
    pub adapterId: LUID,
    pub id: u32,
}

#[repr(C)]
pub struct DISPLAYCONFIG_RATIONAL {
    pub Numerator: u32,
    pub Denominator: u32,
}

#[repr(C)]
pub struct DISPLAYCONFIG_2DREGION {
    pub cx: u32,
    pub cy: u32,
}

#[repr(C)]
pub struct DISPLAYCONFIG_VIDEO_SIGNAL_INFO {
    pub pixelRate: u64,
    pub hSyncFreq: DISPLAYCONFIG_RATIONAL,
    pub vSyncFreq: DISPLAYCONFIG_RATIONAL,
    pub activeSize: DISPLAYCONFIG_2DREGION,
    pub totalSize: DISPLAYCONFIG_2DREGION,
    pub Anonymous: _Anonymous_e__Union,
    pub scanLineOrdering: i32,
}

#[repr(C)]
pub struct DISPLAYCONFIG_TARGET_MODE {
    pub targetVideoSignalInfo: DISPLAYCONFIG_VIDEO_SIGNAL_INFO,
}

#[repr(C)]
pub struct DISPLAYCONFIG_TARGET_PREFERRED_MODE {
    pub header: DISPLAYCONFIG_DEVICE_INFO_HEADER,
    pub width: u32,
    pub height: u32,
    pub targetMode: DISPLAYCONFIG_TARGET_MODE,
}
import "golang.org/x/sys/windows"

type LUID struct {
	LowPart uint32
	HighPart int32
}

type DISPLAYCONFIG_DEVICE_INFO_HEADER struct {
	type int32
	size uint32
	adapterId LUID
	id uint32
}

type DISPLAYCONFIG_RATIONAL struct {
	Numerator uint32
	Denominator uint32
}

type DISPLAYCONFIG_2DREGION struct {
	cx uint32
	cy uint32
}

type DISPLAYCONFIG_VIDEO_SIGNAL_INFO struct {
	pixelRate uint64
	hSyncFreq DISPLAYCONFIG_RATIONAL
	vSyncFreq DISPLAYCONFIG_RATIONAL
	activeSize DISPLAYCONFIG_2DREGION
	totalSize DISPLAYCONFIG_2DREGION
	Anonymous _Anonymous_e__Union
	scanLineOrdering int32
}

type DISPLAYCONFIG_TARGET_MODE struct {
	targetVideoSignalInfo DISPLAYCONFIG_VIDEO_SIGNAL_INFO
}

type DISPLAYCONFIG_TARGET_PREFERRED_MODE struct {
	header DISPLAYCONFIG_DEVICE_INFO_HEADER
	width uint32
	height uint32
	targetMode DISPLAYCONFIG_TARGET_MODE
}
type
  LUID = record
    LowPart: DWORD;
    HighPart: Integer;
  end;

  DISPLAYCONFIG_DEVICE_INFO_HEADER = record
    type: Integer;
    size: DWORD;
    adapterId: LUID;
    id: DWORD;
  end;

  DISPLAYCONFIG_RATIONAL = record
    Numerator: DWORD;
    Denominator: DWORD;
  end;

  DISPLAYCONFIG_2DREGION = record
    cx: DWORD;
    cy: DWORD;
  end;

  DISPLAYCONFIG_VIDEO_SIGNAL_INFO = record
    pixelRate: UInt64;
    hSyncFreq: DISPLAYCONFIG_RATIONAL;
    vSyncFreq: DISPLAYCONFIG_RATIONAL;
    activeSize: DISPLAYCONFIG_2DREGION;
    totalSize: DISPLAYCONFIG_2DREGION;
    Anonymous: _Anonymous_e__Union;
    scanLineOrdering: Integer;
  end;

  DISPLAYCONFIG_TARGET_MODE = record
    targetVideoSignalInfo: DISPLAYCONFIG_VIDEO_SIGNAL_INFO;
  end;

  DISPLAYCONFIG_TARGET_PREFERRED_MODE = record
    header: DISPLAYCONFIG_DEVICE_INFO_HEADER;
    width: DWORD;
    height: DWORD;
    targetMode: DISPLAYCONFIG_TARGET_MODE;
  end;
const LUID = extern struct {
    LowPart: u32,
    HighPart: i32,
};

const DISPLAYCONFIG_DEVICE_INFO_HEADER = extern struct {
    type: i32,
    size: u32,
    adapterId: LUID,
    id: u32,
};

const DISPLAYCONFIG_RATIONAL = extern struct {
    Numerator: u32,
    Denominator: u32,
};

const DISPLAYCONFIG_2DREGION = extern struct {
    cx: u32,
    cy: u32,
};

const DISPLAYCONFIG_VIDEO_SIGNAL_INFO = extern struct {
    pixelRate: u64,
    hSyncFreq: DISPLAYCONFIG_RATIONAL,
    vSyncFreq: DISPLAYCONFIG_RATIONAL,
    activeSize: DISPLAYCONFIG_2DREGION,
    totalSize: DISPLAYCONFIG_2DREGION,
    Anonymous: _Anonymous_e__Union,
    scanLineOrdering: i32,
};

const DISPLAYCONFIG_TARGET_MODE = extern struct {
    targetVideoSignalInfo: DISPLAYCONFIG_VIDEO_SIGNAL_INFO,
};

const DISPLAYCONFIG_TARGET_PREFERRED_MODE = extern struct {
    header: DISPLAYCONFIG_DEVICE_INFO_HEADER,
    width: u32,
    height: u32,
    targetMode: DISPLAYCONFIG_TARGET_MODE,
};
type
  LUID {.bycopy.} = object
    LowPart: uint32
    HighPart: int32

  DISPLAYCONFIG_DEVICE_INFO_HEADER {.bycopy.} = object
    type: int32
    size: uint32
    adapterId: LUID
    id: uint32

  DISPLAYCONFIG_RATIONAL {.bycopy.} = object
    Numerator: uint32
    Denominator: uint32

  DISPLAYCONFIG_2DREGION {.bycopy.} = object
    cx: uint32
    cy: uint32

  DISPLAYCONFIG_VIDEO_SIGNAL_INFO {.bycopy.} = object
    pixelRate: uint64
    hSyncFreq: DISPLAYCONFIG_RATIONAL
    vSyncFreq: DISPLAYCONFIG_RATIONAL
    activeSize: DISPLAYCONFIG_2DREGION
    totalSize: DISPLAYCONFIG_2DREGION
    Anonymous: _Anonymous_e__Union
    scanLineOrdering: int32

  DISPLAYCONFIG_TARGET_MODE {.bycopy.} = object
    targetVideoSignalInfo: DISPLAYCONFIG_VIDEO_SIGNAL_INFO

  DISPLAYCONFIG_TARGET_PREFERRED_MODE {.bycopy.} = object
    header: DISPLAYCONFIG_DEVICE_INFO_HEADER
    width: uint32
    height: uint32
    targetMode: DISPLAYCONFIG_TARGET_MODE
struct LUID
{
    uint LowPart;
    int HighPart;
}

struct DISPLAYCONFIG_DEVICE_INFO_HEADER
{
    int type;
    uint size;
    LUID adapterId;
    uint id;
}

struct DISPLAYCONFIG_RATIONAL
{
    uint Numerator;
    uint Denominator;
}

struct DISPLAYCONFIG_2DREGION
{
    uint cx;
    uint cy;
}

struct DISPLAYCONFIG_VIDEO_SIGNAL_INFO
{
    ulong pixelRate;
    DISPLAYCONFIG_RATIONAL hSyncFreq;
    DISPLAYCONFIG_RATIONAL vSyncFreq;
    DISPLAYCONFIG_2DREGION activeSize;
    DISPLAYCONFIG_2DREGION totalSize;
    _Anonymous_e__Union Anonymous;
    int scanLineOrdering;
}

struct DISPLAYCONFIG_TARGET_MODE
{
    DISPLAYCONFIG_VIDEO_SIGNAL_INFO targetVideoSignalInfo;
}

struct DISPLAYCONFIG_TARGET_PREFERRED_MODE
{
    DISPLAYCONFIG_DEVICE_INFO_HEADER header;
    uint width;
    uint height;
    DISPLAYCONFIG_TARGET_MODE targetMode;
}

HSP用 定義

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

; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x86 レイアウト)
; DISPLAYCONFIG_TARGET_PREFERRED_MODE サイズ: 80 バイト(x86)
dim st, 20    ; 4byte整数×20(構造体サイズ 80 / 4 切り上げ)
; header : DISPLAYCONFIG_DEVICE_INFO_HEADER (+0, 20byte)  varptr(st)+0 を基点に操作(20byte:入れ子/配列)
; width : DWORD (+20, 4byte)  st.5 = 値  /  値 = st.5   (lpoke/lpeek も可)
; height : DWORD (+24, 4byte)  st.6 = 値  /  値 = st.6   (lpoke/lpeek も可)
; targetMode : DISPLAYCONFIG_TARGET_MODE (+32, 48byte)  varptr(st)+32 を基点に操作(48byte:入れ子/配列)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; DISPLAYCONFIG_TARGET_PREFERRED_MODE サイズ: 88 バイト(x64)
dim st, 22    ; 4byte整数×22(構造体サイズ 88 / 4 切り上げ)
; header : DISPLAYCONFIG_DEVICE_INFO_HEADER (+0, 20byte)  varptr(st)+0 を基点に操作(20byte:入れ子/配列)
; width : DWORD (+20, 4byte)  st.5 = 値  /  値 = st.5   (lpoke/lpeek も可)
; height : DWORD (+24, 4byte)  st.6 = 値  /  値 = st.6   (lpoke/lpeek も可)
; targetMode : DISPLAYCONFIG_TARGET_MODE (+32, 56byte)  varptr(st)+32 を基点に操作(56byte:入れ子/配列)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
; ※GUID・入れ子構造体はデフォルト型でないため、依存する #defstruct を先に定義(下記に同梱)。
#defstruct global LUID
    #field int LowPart
    #field int HighPart
#endstruct

#defstruct global DISPLAYCONFIG_DEVICE_INFO_HEADER
    #field int type
    #field int size
    #field LUID adapterId
    #field int id
#endstruct

#defstruct global DISPLAYCONFIG_RATIONAL
    #field int Numerator
    #field int Denominator
#endstruct

#defstruct global DISPLAYCONFIG_2DREGION
    #field int cx
    #field int cy
#endstruct

#defstruct global DISPLAYCONFIG_VIDEO_SIGNAL_INFO
    #field int64 pixelRate
    #field DISPLAYCONFIG_RATIONAL hSyncFreq
    #field DISPLAYCONFIG_RATIONAL vSyncFreq
    #field DISPLAYCONFIG_2DREGION activeSize
    #field DISPLAYCONFIG_2DREGION totalSize
    #field byte Anonymous 8
    #field int scanLineOrdering
#endstruct

#defstruct global DISPLAYCONFIG_TARGET_MODE
    #field DISPLAYCONFIG_VIDEO_SIGNAL_INFO targetVideoSignalInfo
#endstruct

#defstruct global DISPLAYCONFIG_TARGET_PREFERRED_MODE
    #field DISPLAYCONFIG_DEVICE_INFO_HEADER header
    #field int width
    #field int height
    #field DISPLAYCONFIG_TARGET_MODE targetMode
#endstruct

stdim st, DISPLAYCONFIG_TARGET_PREFERRED_MODE        ; NSTRUCT 変数を確保
st->width = 100
mes "width=" + st->width