Win32 API 日本語リファレンス
ホームUI.Shell › SHChangeDWORDAsIDList

SHChangeDWORDAsIDList

構造体
サイズx64: 12 バイト / x86: 12 バイトパッキング1

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

フィールド

フィールドサイズx64x86説明
cbWORD2+0+0構造体のサイズ (バイト単位)。
dwItem1DWORD4+2+21 番目の DWORD 値。
dwItem2DWORD4+6+62 番目の DWORD 値。
cbZeroWORD2+10+10

公式ドキュメント

[SHChangeDWORDAsIDList は、「要件」セクションに示されているオペレーティングシステムで使用できます。以降のバージョンでは変更されるか、使用できなくなる可能性があります。]

2 つの DWORD 値を ITEMIDLIST を模倣した形式で格納し、SHChangeNotify で使用できるようにします。

解説(Remarks)

この例では、SHChangeUpdateImageIDListSHChangeDWORDAsIDListSHChangeNotify で使用して、SHUpdateImage 関数の動作を模倣する方法を示します。

void MyUpdateImage(LPCWSTR pszHashItem, int iIndex, UINT uFlags, int iImageIndex)
{
    SHChangeUpdateImageIDList rgPidl;
    SHChangeDWORDAsIDList rgDWord;
    int cchLen;
    USHORT *pcb;

    // Validate parameters: iImageIndex must be a valid system image list value.
    if (iImageIndex < 0)
    {
        return;
    }

    // Validate parameters: pszHashItem must not exceed MAX_PATH in length
    cchLen = lstrlenW(pszHashItem);
    if (cchLen >= MAX_PATH)
    {
        return;
    }

    // Load SHChangeUpdateImageIDList
    rgPidl.dwProcessID = GetCurrentProcessId();
    rgPidl.iIconIndex = iIndex;
    rgPidl.iCurIndex = iImageIndex;
    rgPidl.uFlags = uFlags;
    lstrcpynW(rgPidl.szName, pszHashItem, MAX_PATH);
    pcb = &rgPidl.szName[cchLen+1];
    
    // Set the size of the first element
    rgPidl.cb = (USHORT)((BYTE*)pcb - (BYTE*)rgPidl); 
    
    // Terminate the "ITEMIDLIST"
    *pcb = 0; 

    // Load SHChangeDWORDAsIDList
    rgDWord.cb = (USHORT)FIELD_OFFSET(SHChangeDWORDAsIDList, cbZero);
    rgDWord.dwItem1 = iImageIndex;
    rgDWord.dwItem2 = 0;
    rgDWord.cbZero = 0;

    // Parameters are now in the form that SHCNE_UPDATEIMAGE can accept
    SHChangeNotify(SHCNE_UPDATEIMAGE, SHCNF_IDLIST, &rgDWord, &rgPidl);
}
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での定義

#include <windows.h>

// SHChangeDWORDAsIDList  (x64 12 / x86 12 バイト)
#pragma pack(push, 1)
typedef struct SHChangeDWORDAsIDList {
    WORD cb;
    DWORD dwItem1;
    DWORD dwItem2;
    WORD cbZero;
} SHChangeDWORDAsIDList;
#pragma pack(pop)
using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Unicode)]
public struct SHChangeDWORDAsIDList
{
    public ushort cb;
    public uint dwItem1;
    public uint dwItem2;
    public ushort cbZero;
}
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential, Pack:=1, CharSet:=CharSet.Unicode)>
Public Structure SHChangeDWORDAsIDList
    Public cb As UShort
    Public dwItem1 As UInteger
    Public dwItem2 As UInteger
    Public cbZero As UShort
End Structure
import ctypes
from ctypes import wintypes

class SHChangeDWORDAsIDList(ctypes.Structure):
    _pack_ = 1
    _fields_ = [
        ("cb", ctypes.c_ushort),
        ("dwItem1", wintypes.DWORD),
        ("dwItem2", wintypes.DWORD),
        ("cbZero", ctypes.c_ushort),
    ]
#[repr(C, packed(1))]
pub struct SHChangeDWORDAsIDList {
    pub cb: u16,
    pub dwItem1: u32,
    pub dwItem2: u32,
    pub cbZero: u16,
}
import "golang.org/x/sys/windows"

type SHChangeDWORDAsIDList struct {
	cb uint16
	dwItem1 uint32
	dwItem2 uint32
	cbZero uint16
}
type
  SHChangeDWORDAsIDList = packed record
    cb: Word;
    dwItem1: DWORD;
    dwItem2: DWORD;
    cbZero: Word;
  end;
const SHChangeDWORDAsIDList = extern struct {
    cb: u16,
    dwItem1: u32,
    dwItem2: u32,
    cbZero: u16,
};
type
  SHChangeDWORDAsIDList {.packed.} = object
    cb: uint16
    dwItem1: uint32
    dwItem2: uint32
    cbZero: uint16
align(1)
struct SHChangeDWORDAsIDList
{
    ushort cb;
    uint dwItem1;
    uint dwItem2;
    ushort cbZero;
}

HSP用 定義

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

; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; SHChangeDWORDAsIDList サイズ: 12 バイト(x64)
dim st, 3    ; 4byte整数×3(構造体サイズ 12 / 4 切り上げ)
; cb : WORD (+0, 2byte)  wpoke st,0,値  /  値 = wpeek(st,0)
; dwItem1 : DWORD (+2, 4byte)  lpoke st,2,値  /  値 = lpeek(st,2)
; dwItem2 : DWORD (+6, 4byte)  lpoke st,6,値  /  値 = lpeek(st,6)
; cbZero : WORD (+10, 2byte)  wpoke st,10,値  /  値 = wpeek(st,10)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
#defstruct global SHChangeDWORDAsIDList, pack=1
    #field short cb
    #field int dwItem1
    #field int dwItem2
    #field short cbZero
#endstruct

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