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

OPENFILENAMEW

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

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

フィールド

フィールドサイズx64x86説明
lStructSizeDWORD4+0+0この構造体のサイズをバイト単位で指定する。GetOpenFileNameW等の呼び出し前に設定する。
hwndOwnerHWND8/4+4+4ダイアログを所有する親ウィンドウのハンドル。NULL可。
hInstanceHINSTANCE8/4+12+8カスタムテンプレートを含むモジュールのインスタンスハンドル。
lpstrFilterLPWSTR8/4+20+12ファイル種別フィルタを表すヌル区切り文字列のペア。最後は二重ヌルで終端する。NULL可。
lpstrCustomFilterLPWSTR8/4+28+16ユーザー選択フィルタを保持する文字列バッファ。NULL可。
nMaxCustFilterDWORD4+36+20lpstrCustomFilterバッファのサイズを文字数で指定する。
nFilterIndexDWORD4+40+24初期選択するフィルタの1始まりのインデックス。0はカスタムフィルタを示す。
lpstrFileLPWSTR8/4+44+28初期ファイル名と選択結果のフルパスを保持するバッファ。複数選択時はヌル区切り。
nMaxFileDWORD4+52+32lpstrFileバッファのサイズを文字数で指定する。
lpstrFileTitleLPWSTR8/4+56+36選択ファイルのファイル名部分(パスなし)を受け取るバッファ。NULL可。
nMaxFileTitleDWORD4+64+40lpstrFileTitleバッファのサイズを文字数で指定する。
lpstrInitialDirLPWSTR8/4+68+44初期表示するディレクトリのパス。NULL可。
lpstrTitleLPWSTR8/4+76+48ダイアログのタイトルバーに表示する文字列。NULL可。
FlagsOPEN_FILENAME_FLAGS4+84+52ダイアログの動作を制御するOFN_系フラグの組み合わせ。
nFileOffsetWORD2+88+56lpstrFile内でファイル名が始まる位置を文字単位で受け取る。
nFileExtensionWORD2+90+58lpstrFile内で拡張子が始まる位置を文字単位で受け取る。
lpstrDefExtLPWSTR8/4+92+60拡張子省略時に付加される既定の拡張子。先頭ピリオドなし。NULL可。
lCustDataLPARAM8/4+100+64フックプロシージャに渡されるアプリケーション定義データ。
lpfnHookLPOFNHOOKPROC8/4+108+68メッセージを処理するフックプロシージャへのポインタ。OFN_ENABLEHOOK時に有効。
lpTemplateNameLPWSTR8/4+116+72OFN_ENABLETEMPLATE指定時のダイアログテンプレートのリソース名。
pvReservedvoid*8/4+124+76予約フィールド。NULLを指定する。
dwReservedDWORD4+132+80予約フィールド。0を指定する。
FlagsExOPEN_FILENAME_FLAGS_EX4+136+84拡張動作を制御するOFN_EX_系フラグ。OFN_EX_NOPLACESBAR等を指定する。

各言語での定義

#include <windows.h>

// OPENFILENAMEW  (x64 140 / x86 88 バイト)
#pragma pack(push, 1)
typedef struct OPENFILENAMEW {
    DWORD lStructSize;
    HWND hwndOwner;
    HINSTANCE hInstance;
    LPWSTR lpstrFilter;
    LPWSTR lpstrCustomFilter;
    DWORD nMaxCustFilter;
    DWORD nFilterIndex;
    LPWSTR lpstrFile;
    DWORD nMaxFile;
    LPWSTR lpstrFileTitle;
    DWORD nMaxFileTitle;
    LPWSTR lpstrInitialDir;
    LPWSTR lpstrTitle;
    OPEN_FILENAME_FLAGS Flags;
    WORD nFileOffset;
    WORD nFileExtension;
    LPWSTR lpstrDefExt;
    LPARAM lCustData;
    LPOFNHOOKPROC lpfnHook;
    LPWSTR lpTemplateName;
    void* pvReserved;
    DWORD dwReserved;
    OPEN_FILENAME_FLAGS_EX FlagsEx;
} OPENFILENAMEW;
#pragma pack(pop)
using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Unicode)]
public struct OPENFILENAMEW
{
    public uint lStructSize;
    public IntPtr hwndOwner;
    public IntPtr hInstance;
    public IntPtr lpstrFilter;
    public IntPtr lpstrCustomFilter;
    public uint nMaxCustFilter;
    public uint nFilterIndex;
    public IntPtr lpstrFile;
    public uint nMaxFile;
    public IntPtr lpstrFileTitle;
    public uint nMaxFileTitle;
    public IntPtr lpstrInitialDir;
    public IntPtr lpstrTitle;
    public uint Flags;
    public ushort nFileOffset;
    public ushort nFileExtension;
    public IntPtr lpstrDefExt;
    public IntPtr lCustData;
    public IntPtr lpfnHook;
    public IntPtr lpTemplateName;
    public IntPtr pvReserved;
    public uint dwReserved;
    public uint FlagsEx;
}
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential, Pack:=1, CharSet:=CharSet.Unicode)>
Public Structure OPENFILENAMEW
    Public lStructSize As UInteger
    Public hwndOwner As IntPtr
    Public hInstance As IntPtr
    Public lpstrFilter As IntPtr
    Public lpstrCustomFilter As IntPtr
    Public nMaxCustFilter As UInteger
    Public nFilterIndex As UInteger
    Public lpstrFile As IntPtr
    Public nMaxFile As UInteger
    Public lpstrFileTitle As IntPtr
    Public nMaxFileTitle As UInteger
    Public lpstrInitialDir As IntPtr
    Public lpstrTitle As IntPtr
    Public Flags As UInteger
    Public nFileOffset As UShort
    Public nFileExtension As UShort
    Public lpstrDefExt As IntPtr
    Public lCustData As IntPtr
    Public lpfnHook As IntPtr
    Public lpTemplateName As IntPtr
    Public pvReserved As IntPtr
    Public dwReserved As UInteger
    Public FlagsEx As UInteger
End Structure
import ctypes
from ctypes import wintypes

class OPENFILENAMEW(ctypes.Structure):
    _pack_ = 1
    _fields_ = [
        ("lStructSize", wintypes.DWORD),
        ("hwndOwner", ctypes.c_void_p),
        ("hInstance", ctypes.c_void_p),
        ("lpstrFilter", ctypes.c_void_p),
        ("lpstrCustomFilter", ctypes.c_void_p),
        ("nMaxCustFilter", wintypes.DWORD),
        ("nFilterIndex", wintypes.DWORD),
        ("lpstrFile", ctypes.c_void_p),
        ("nMaxFile", wintypes.DWORD),
        ("lpstrFileTitle", ctypes.c_void_p),
        ("nMaxFileTitle", wintypes.DWORD),
        ("lpstrInitialDir", ctypes.c_void_p),
        ("lpstrTitle", ctypes.c_void_p),
        ("Flags", wintypes.DWORD),
        ("nFileOffset", ctypes.c_ushort),
        ("nFileExtension", ctypes.c_ushort),
        ("lpstrDefExt", ctypes.c_void_p),
        ("lCustData", ctypes.c_ssize_t),
        ("lpfnHook", ctypes.c_void_p),
        ("lpTemplateName", ctypes.c_void_p),
        ("pvReserved", ctypes.c_void_p),
        ("dwReserved", wintypes.DWORD),
        ("FlagsEx", wintypes.DWORD),
    ]
#[repr(C, packed(1))]
pub struct OPENFILENAMEW {
    pub lStructSize: u32,
    pub hwndOwner: *mut core::ffi::c_void,
    pub hInstance: *mut core::ffi::c_void,
    pub lpstrFilter: *mut core::ffi::c_void,
    pub lpstrCustomFilter: *mut core::ffi::c_void,
    pub nMaxCustFilter: u32,
    pub nFilterIndex: u32,
    pub lpstrFile: *mut core::ffi::c_void,
    pub nMaxFile: u32,
    pub lpstrFileTitle: *mut core::ffi::c_void,
    pub nMaxFileTitle: u32,
    pub lpstrInitialDir: *mut core::ffi::c_void,
    pub lpstrTitle: *mut core::ffi::c_void,
    pub Flags: u32,
    pub nFileOffset: u16,
    pub nFileExtension: u16,
    pub lpstrDefExt: *mut core::ffi::c_void,
    pub lCustData: isize,
    pub lpfnHook: *mut core::ffi::c_void,
    pub lpTemplateName: *mut core::ffi::c_void,
    pub pvReserved: *mut core::ffi::c_void,
    pub dwReserved: u32,
    pub FlagsEx: u32,
}
import "golang.org/x/sys/windows"

type OPENFILENAMEW struct {
	lStructSize uint32
	hwndOwner uintptr
	hInstance uintptr
	lpstrFilter uintptr
	lpstrCustomFilter uintptr
	nMaxCustFilter uint32
	nFilterIndex uint32
	lpstrFile uintptr
	nMaxFile uint32
	lpstrFileTitle uintptr
	nMaxFileTitle uint32
	lpstrInitialDir uintptr
	lpstrTitle uintptr
	Flags uint32
	nFileOffset uint16
	nFileExtension uint16
	lpstrDefExt uintptr
	lCustData uintptr
	lpfnHook uintptr
	lpTemplateName uintptr
	pvReserved uintptr
	dwReserved uint32
	FlagsEx uint32
}
type
  OPENFILENAMEW = packed record
    lStructSize: DWORD;
    hwndOwner: Pointer;
    hInstance: Pointer;
    lpstrFilter: Pointer;
    lpstrCustomFilter: Pointer;
    nMaxCustFilter: DWORD;
    nFilterIndex: DWORD;
    lpstrFile: Pointer;
    nMaxFile: DWORD;
    lpstrFileTitle: Pointer;
    nMaxFileTitle: DWORD;
    lpstrInitialDir: Pointer;
    lpstrTitle: Pointer;
    Flags: DWORD;
    nFileOffset: Word;
    nFileExtension: Word;
    lpstrDefExt: Pointer;
    lCustData: NativeInt;
    lpfnHook: Pointer;
    lpTemplateName: Pointer;
    pvReserved: Pointer;
    dwReserved: DWORD;
    FlagsEx: DWORD;
  end;
const OPENFILENAMEW = extern struct {
    lStructSize: u32,
    hwndOwner: ?*anyopaque,
    hInstance: ?*anyopaque,
    lpstrFilter: ?*anyopaque,
    lpstrCustomFilter: ?*anyopaque,
    nMaxCustFilter: u32,
    nFilterIndex: u32,
    lpstrFile: ?*anyopaque,
    nMaxFile: u32,
    lpstrFileTitle: ?*anyopaque,
    nMaxFileTitle: u32,
    lpstrInitialDir: ?*anyopaque,
    lpstrTitle: ?*anyopaque,
    Flags: u32,
    nFileOffset: u16,
    nFileExtension: u16,
    lpstrDefExt: ?*anyopaque,
    lCustData: isize,
    lpfnHook: ?*anyopaque,
    lpTemplateName: ?*anyopaque,
    pvReserved: ?*anyopaque,
    dwReserved: u32,
    FlagsEx: u32,
};
type
  OPENFILENAMEW {.packed.} = object
    lStructSize: uint32
    hwndOwner: pointer
    hInstance: pointer
    lpstrFilter: pointer
    lpstrCustomFilter: pointer
    nMaxCustFilter: uint32
    nFilterIndex: uint32
    lpstrFile: pointer
    nMaxFile: uint32
    lpstrFileTitle: pointer
    nMaxFileTitle: uint32
    lpstrInitialDir: pointer
    lpstrTitle: pointer
    Flags: uint32
    nFileOffset: uint16
    nFileExtension: uint16
    lpstrDefExt: pointer
    lCustData: int
    lpfnHook: pointer
    lpTemplateName: pointer
    pvReserved: pointer
    dwReserved: uint32
    FlagsEx: uint32
align(1)
struct OPENFILENAMEW
{
    uint lStructSize;
    void* hwndOwner;
    void* hInstance;
    void* lpstrFilter;
    void* lpstrCustomFilter;
    uint nMaxCustFilter;
    uint nFilterIndex;
    void* lpstrFile;
    uint nMaxFile;
    void* lpstrFileTitle;
    uint nMaxFileTitle;
    void* lpstrInitialDir;
    void* lpstrTitle;
    uint Flags;
    ushort nFileOffset;
    ushort nFileExtension;
    void* lpstrDefExt;
    ptrdiff_t lCustData;
    void* lpfnHook;
    void* lpTemplateName;
    void* pvReserved;
    uint dwReserved;
    uint FlagsEx;
}

HSP用 定義

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

; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x86 レイアウト)
; OPENFILENAMEW サイズ: 88 バイト(x86)
dim st, 22    ; 4byte整数×22(構造体サイズ 88 / 4 切り上げ)
; lStructSize : DWORD (+0, 4byte)  st.0 = 値  /  値 = st.0   (lpoke/lpeek も可)
; hwndOwner : HWND (+4, 4byte)  st.1 = 値  /  値 = st.1   (lpoke/lpeek も可)
; hInstance : HINSTANCE (+8, 4byte)  st.2 = 値  /  値 = st.2   (lpoke/lpeek も可)
; lpstrFilter : LPWSTR (+12, 4byte)  st.3 = 値  /  値 = st.3   (lpoke/lpeek も可)
; lpstrCustomFilter : LPWSTR (+16, 4byte)  st.4 = 値  /  値 = st.4   (lpoke/lpeek も可)
; nMaxCustFilter : DWORD (+20, 4byte)  st.5 = 値  /  値 = st.5   (lpoke/lpeek も可)
; nFilterIndex : DWORD (+24, 4byte)  st.6 = 値  /  値 = st.6   (lpoke/lpeek も可)
; lpstrFile : LPWSTR (+28, 4byte)  st.7 = 値  /  値 = st.7   (lpoke/lpeek も可)
; nMaxFile : DWORD (+32, 4byte)  st.8 = 値  /  値 = st.8   (lpoke/lpeek も可)
; lpstrFileTitle : LPWSTR (+36, 4byte)  st.9 = 値  /  値 = st.9   (lpoke/lpeek も可)
; nMaxFileTitle : DWORD (+40, 4byte)  st.10 = 値  /  値 = st.10   (lpoke/lpeek も可)
; lpstrInitialDir : LPWSTR (+44, 4byte)  st.11 = 値  /  値 = st.11   (lpoke/lpeek も可)
; lpstrTitle : LPWSTR (+48, 4byte)  st.12 = 値  /  値 = st.12   (lpoke/lpeek も可)
; Flags : OPEN_FILENAME_FLAGS (+52, 4byte)  st.13 = 値  /  値 = st.13   (lpoke/lpeek も可)
; nFileOffset : WORD (+56, 2byte)  wpoke st,56,値  /  値 = wpeek(st,56)
; nFileExtension : WORD (+58, 2byte)  wpoke st,58,値  /  値 = wpeek(st,58)
; lpstrDefExt : LPWSTR (+60, 4byte)  st.15 = 値  /  値 = st.15   (lpoke/lpeek も可)
; lCustData : LPARAM (+64, 4byte)  st.16 = 値  /  値 = st.16   (lpoke/lpeek も可)
; lpfnHook : LPOFNHOOKPROC (+68, 4byte)  st.17 = 値  /  値 = st.17   (lpoke/lpeek も可)
; lpTemplateName : LPWSTR (+72, 4byte)  st.18 = 値  /  値 = st.18   (lpoke/lpeek も可)
; pvReserved : void* (+76, 4byte)  st.19 = 値  /  値 = st.19   (lpoke/lpeek も可)
; dwReserved : DWORD (+80, 4byte)  st.20 = 値  /  値 = st.20   (lpoke/lpeek も可)
; FlagsEx : OPEN_FILENAME_FLAGS_EX (+84, 4byte)  st.21 = 値  /  値 = st.21   (lpoke/lpeek も可)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; OPENFILENAMEW サイズ: 140 バイト(x64)
dim st, 35    ; 4byte整数×35(構造体サイズ 140 / 4 切り上げ)
; lStructSize : DWORD (+0, 4byte)  st.0 = 値  /  値 = st.0   (lpoke/lpeek も可)
; hwndOwner : HWND (+4, 8byte)  qpoke st,4,値 / qpeek(st,4)  ※IronHSPのみ。3.7/3.8は lpoke st,4,下位 : lpoke st,8,上位
; hInstance : HINSTANCE (+12, 8byte)  qpoke st,12,値 / qpeek(st,12)  ※IronHSPのみ。3.7/3.8は lpoke st,12,下位 : lpoke st,16,上位
; lpstrFilter : LPWSTR (+20, 8byte)  qpoke st,20,値 / qpeek(st,20)  ※IronHSPのみ。3.7/3.8は lpoke st,20,下位 : lpoke st,24,上位
; lpstrCustomFilter : LPWSTR (+28, 8byte)  qpoke st,28,値 / qpeek(st,28)  ※IronHSPのみ。3.7/3.8は lpoke st,28,下位 : lpoke st,32,上位
; nMaxCustFilter : DWORD (+36, 4byte)  st.9 = 値  /  値 = st.9   (lpoke/lpeek も可)
; nFilterIndex : DWORD (+40, 4byte)  st.10 = 値  /  値 = st.10   (lpoke/lpeek も可)
; lpstrFile : LPWSTR (+44, 8byte)  qpoke st,44,値 / qpeek(st,44)  ※IronHSPのみ。3.7/3.8は lpoke st,44,下位 : lpoke st,48,上位
; nMaxFile : DWORD (+52, 4byte)  st.13 = 値  /  値 = st.13   (lpoke/lpeek も可)
; lpstrFileTitle : LPWSTR (+56, 8byte)  qpoke st,56,値 / qpeek(st,56)  ※IronHSPのみ。3.7/3.8は lpoke st,56,下位 : lpoke st,60,上位
; nMaxFileTitle : DWORD (+64, 4byte)  st.16 = 値  /  値 = st.16   (lpoke/lpeek も可)
; lpstrInitialDir : LPWSTR (+68, 8byte)  qpoke st,68,値 / qpeek(st,68)  ※IronHSPのみ。3.7/3.8は lpoke st,68,下位 : lpoke st,72,上位
; lpstrTitle : LPWSTR (+76, 8byte)  qpoke st,76,値 / qpeek(st,76)  ※IronHSPのみ。3.7/3.8は lpoke st,76,下位 : lpoke st,80,上位
; Flags : OPEN_FILENAME_FLAGS (+84, 4byte)  st.21 = 値  /  値 = st.21   (lpoke/lpeek も可)
; nFileOffset : WORD (+88, 2byte)  wpoke st,88,値  /  値 = wpeek(st,88)
; nFileExtension : WORD (+90, 2byte)  wpoke st,90,値  /  値 = wpeek(st,90)
; lpstrDefExt : LPWSTR (+92, 8byte)  qpoke st,92,値 / qpeek(st,92)  ※IronHSPのみ。3.7/3.8は lpoke st,92,下位 : lpoke st,96,上位
; lCustData : LPARAM (+100, 8byte)  qpoke st,100,値 / qpeek(st,100)  ※IronHSPのみ。3.7/3.8は lpoke st,100,下位 : lpoke st,104,上位
; lpfnHook : LPOFNHOOKPROC (+108, 8byte)  qpoke st,108,値 / qpeek(st,108)  ※IronHSPのみ。3.7/3.8は lpoke st,108,下位 : lpoke st,112,上位
; lpTemplateName : LPWSTR (+116, 8byte)  qpoke st,116,値 / qpeek(st,116)  ※IronHSPのみ。3.7/3.8は lpoke st,116,下位 : lpoke st,120,上位
; pvReserved : void* (+124, 8byte)  qpoke st,124,値 / qpeek(st,124)  ※IronHSPのみ。3.7/3.8は lpoke st,124,下位 : lpoke st,128,上位
; dwReserved : DWORD (+132, 4byte)  st.33 = 値  /  値 = st.33   (lpoke/lpeek も可)
; FlagsEx : OPEN_FILENAME_FLAGS_EX (+136, 4byte)  st.34 = 値  /  値 = st.34   (lpoke/lpeek も可)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
#defstruct global OPENFILENAMEW, pack=1
    #field int lStructSize
    #field intptr hwndOwner
    #field intptr hInstance
    #field intptr lpstrFilter
    #field intptr lpstrCustomFilter
    #field int nMaxCustFilter
    #field int nFilterIndex
    #field intptr lpstrFile
    #field int nMaxFile
    #field intptr lpstrFileTitle
    #field int nMaxFileTitle
    #field intptr lpstrInitialDir
    #field intptr lpstrTitle
    #field int Flags
    #field short nFileOffset
    #field short nFileExtension
    #field intptr lpstrDefExt
    #field intptr lCustData
    #field intptr lpfnHook
    #field intptr lpTemplateName
    #field intptr pvReserved
    #field int dwReserved
    #field int FlagsEx
#endstruct

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