DlgDirListA
関数シグネチャ
// USER32.dll (ANSI / -A)
#include <windows.h>
INT DlgDirListA(
HWND hDlg,
LPSTR lpPathSpec,
INT nIDListBox,
INT nIDStaticPath,
DLG_DIR_LIST_FILE_TYPE uFileType
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| hDlg | HWND | in | リストボックスを含むダイアログボックスへのハンドルです。 | ||||||||||||||||||||
| lpPathSpec | LPSTR | inout | 絶対パス、相対パス、またはファイル名を指定する null 終端文字列を格納したバッファーへのポインターです。絶対パスは、ドライブ文字(例: d:)または UNC 名(例: \<i>machinename\sharename)で始めることができます。 この関数は文字列をディレクトリとファイル名に分割します。関数は、ファイル名に一致する名前をディレクトリ内で検索します。文字列がディレクトリを指定していない場合、関数は現在のディレクトリを検索します。 文字列にファイル名が含まれる場合、そのファイル名には少なくとも 1 つのワイルドカード文字(? または *)を含める必要があります。文字列にファイル名が含まれていない場合、関数はアスタリスクのワイルドカード文字(*)をファイル名として指定したものとして動作します。指定されたディレクトリ内で、ファイル名に一致し、かつ uFileType パラメーターで指定された属性を持つすべての名前がリストボックスに追加されます。 | ||||||||||||||||||||
| nIDListBox | INT | in | hDlg ダイアログボックス内のリストボックスの識別子です。このパラメーターが 0 の場合、DlgDirList はリストボックスへの設定を行いません。 | ||||||||||||||||||||
| nIDStaticPath | INT | in | hDlg ダイアログボックス内のスタティックコントロールの識別子です。DlgDirList は、このコントロールのテキストを現在のドライブとディレクトリを表示するように設定します。現在のドライブとディレクトリを表示しない場合、このパラメーターは 0 にできます。 | ||||||||||||||||||||
| uFileType | DLG_DIR_LIST_FILE_TYPE | in | リストボックスに追加するファイルまたはディレクトリの属性を指定します。このパラメーターには、次の値のうち 1 つ以上を指定できます。
|
戻り値の型: INT
公式ドキュメント
リストボックスの内容を、指定したディレクトリ内のサブディレクトリおよびファイルの名前で置き換えます。ファイル属性のセットを指定することで、名前の一覧をフィルターできます。一覧には、必要に応じてマップされたドライブを含めることもできます。(ANSI)
戻り値
型: int
関数が成功した場合、戻り値は 0 以外になります。
関数が失敗した場合、戻り値は 0 になります。たとえば、 lpPathSpec で指定された文字列が有効なパスでない場合、関数は失敗します。拡張エラー情報を取得するには、 を呼び出します。
解説(Remarks)
lpPathSpec がディレクトリを指定している場合、DlgDirListComboBox はリストボックスへの設定を行う前に、現在のディレクトリを指定されたディレクトリに変更します。nIDStaticPath パラメーターで識別されるスタティックコントロールのテキストは、新しい現在のディレクトリの名前に設定されます。
DlgDirList は、リストボックスに LB_RESETCONTENT および LB_DIR メッセージを送信します。
uFileType に DDL_DIRECTORY フラグが含まれ、かつ lpPathSpec が C:\TEMP のような第 1 階層のディレクトリを指定している場合、リストボックスには常にルートディレクトリを表す ".." エントリが含まれます。これは、ルートディレクトリに隠し属性やシステム属性があり、DDL_HIDDEN フラグや DDL_SYSTEM フラグが指定されていない場合でも同様です。NTFS ボリュームのルートディレクトリには隠し属性とシステム属性があります。
ディレクトリの一覧には、長いファイル名がある場合はそれが表示されます。
例
例については、次のトピックを参照してください: 単一選択リストボックスでのディレクトリ一覧の作成 および 複数選択リストボックスの作成。
winuser.h ヘッダーは DlgDirList を、UNICODE プリプロセッサ定数の定義に基づいてこの関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして定義します。エンコーディング中立なエイリアスの使用を、エンコーディング中立でないコードと混在させると、コンパイルエラーや実行時エラーを引き起こす不整合につながる可能性があります。詳細については、関数プロトタイプの規則を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// USER32.dll (ANSI / -A)
#include <windows.h>
INT DlgDirListA(
HWND hDlg,
LPSTR lpPathSpec,
INT nIDListBox,
INT nIDStaticPath,
DLG_DIR_LIST_FILE_TYPE uFileType
);[DllImport("USER32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern int DlgDirListA(
IntPtr hDlg, // HWND
[MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpPathSpec, // LPSTR in/out
int nIDListBox, // INT
int nIDStaticPath, // INT
uint uFileType // DLG_DIR_LIST_FILE_TYPE
);<DllImport("USER32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function DlgDirListA(
hDlg As IntPtr, ' HWND
<MarshalAs(UnmanagedType.LPStr)> lpPathSpec As System.Text.StringBuilder, ' LPSTR in/out
nIDListBox As Integer, ' INT
nIDStaticPath As Integer, ' INT
uFileType As UInteger ' DLG_DIR_LIST_FILE_TYPE
) As Integer
End Function' hDlg : HWND
' lpPathSpec : LPSTR in/out
' nIDListBox : INT
' nIDStaticPath : INT
' uFileType : DLG_DIR_LIST_FILE_TYPE
Declare PtrSafe Function DlgDirListA Lib "user32" ( _
ByVal hDlg As LongPtr, _
ByVal lpPathSpec As String, _
ByVal nIDListBox As Long, _
ByVal nIDStaticPath As Long, _
ByVal uFileType As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
DlgDirListA = ctypes.windll.user32.DlgDirListA
DlgDirListA.restype = ctypes.c_int
DlgDirListA.argtypes = [
wintypes.HANDLE, # hDlg : HWND
wintypes.LPSTR, # lpPathSpec : LPSTR in/out
ctypes.c_int, # nIDListBox : INT
ctypes.c_int, # nIDStaticPath : INT
wintypes.DWORD, # uFileType : DLG_DIR_LIST_FILE_TYPE
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('USER32.dll')
DlgDirListA = Fiddle::Function.new(
lib['DlgDirListA'],
[
Fiddle::TYPE_VOIDP, # hDlg : HWND
Fiddle::TYPE_VOIDP, # lpPathSpec : LPSTR in/out
Fiddle::TYPE_INT, # nIDListBox : INT
Fiddle::TYPE_INT, # nIDStaticPath : INT
-Fiddle::TYPE_INT, # uFileType : DLG_DIR_LIST_FILE_TYPE
],
Fiddle::TYPE_INT)#[link(name = "user32")]
extern "system" {
fn DlgDirListA(
hDlg: *mut core::ffi::c_void, // HWND
lpPathSpec: *mut u8, // LPSTR in/out
nIDListBox: i32, // INT
nIDStaticPath: i32, // INT
uFileType: u32 // DLG_DIR_LIST_FILE_TYPE
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("USER32.dll", CharSet = CharSet.Ansi)]
public static extern int DlgDirListA(IntPtr hDlg, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpPathSpec, int nIDListBox, int nIDStaticPath, uint uFileType);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_DlgDirListA' -Namespace Win32 -PassThru
# $api::DlgDirListA(hDlg, lpPathSpec, nIDListBox, nIDStaticPath, uFileType)#uselib "USER32.dll"
#func global DlgDirListA "DlgDirListA" sptr, sptr, sptr, sptr, sptr
; DlgDirListA hDlg, varptr(lpPathSpec), nIDListBox, nIDStaticPath, uFileType ; 戻り値は stat
; hDlg : HWND -> "sptr"
; lpPathSpec : LPSTR in/out -> "sptr"
; nIDListBox : INT -> "sptr"
; nIDStaticPath : INT -> "sptr"
; uFileType : DLG_DIR_LIST_FILE_TYPE -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "USER32.dll" #cfunc global DlgDirListA "DlgDirListA" sptr, var, int, int, int ; res = DlgDirListA(hDlg, lpPathSpec, nIDListBox, nIDStaticPath, uFileType) ; hDlg : HWND -> "sptr" ; lpPathSpec : LPSTR in/out -> "var" ; nIDListBox : INT -> "int" ; nIDStaticPath : INT -> "int" ; uFileType : DLG_DIR_LIST_FILE_TYPE -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "USER32.dll" #cfunc global DlgDirListA "DlgDirListA" sptr, sptr, int, int, int ; res = DlgDirListA(hDlg, varptr(lpPathSpec), nIDListBox, nIDStaticPath, uFileType) ; hDlg : HWND -> "sptr" ; lpPathSpec : LPSTR in/out -> "sptr" ; nIDListBox : INT -> "int" ; nIDStaticPath : INT -> "int" ; uFileType : DLG_DIR_LIST_FILE_TYPE -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; INT DlgDirListA(HWND hDlg, LPSTR lpPathSpec, INT nIDListBox, INT nIDStaticPath, DLG_DIR_LIST_FILE_TYPE uFileType) #uselib "USER32.dll" #cfunc global DlgDirListA "DlgDirListA" intptr, var, int, int, int ; res = DlgDirListA(hDlg, lpPathSpec, nIDListBox, nIDStaticPath, uFileType) ; hDlg : HWND -> "intptr" ; lpPathSpec : LPSTR in/out -> "var" ; nIDListBox : INT -> "int" ; nIDStaticPath : INT -> "int" ; uFileType : DLG_DIR_LIST_FILE_TYPE -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; INT DlgDirListA(HWND hDlg, LPSTR lpPathSpec, INT nIDListBox, INT nIDStaticPath, DLG_DIR_LIST_FILE_TYPE uFileType) #uselib "USER32.dll" #cfunc global DlgDirListA "DlgDirListA" intptr, intptr, int, int, int ; res = DlgDirListA(hDlg, varptr(lpPathSpec), nIDListBox, nIDStaticPath, uFileType) ; hDlg : HWND -> "intptr" ; lpPathSpec : LPSTR in/out -> "intptr" ; nIDListBox : INT -> "int" ; nIDStaticPath : INT -> "int" ; uFileType : DLG_DIR_LIST_FILE_TYPE -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
user32 = windows.NewLazySystemDLL("USER32.dll")
procDlgDirListA = user32.NewProc("DlgDirListA")
)
// hDlg (HWND), lpPathSpec (LPSTR in/out), nIDListBox (INT), nIDStaticPath (INT), uFileType (DLG_DIR_LIST_FILE_TYPE)
r1, _, err := procDlgDirListA.Call(
uintptr(hDlg),
uintptr(lpPathSpec),
uintptr(nIDListBox),
uintptr(nIDStaticPath),
uintptr(uFileType),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // INTfunction DlgDirListA(
hDlg: THandle; // HWND
lpPathSpec: PAnsiChar; // LPSTR in/out
nIDListBox: Integer; // INT
nIDStaticPath: Integer; // INT
uFileType: DWORD // DLG_DIR_LIST_FILE_TYPE
): Integer; stdcall;
external 'USER32.dll' name 'DlgDirListA';result := DllCall("USER32\DlgDirListA"
, "Ptr", hDlg ; HWND
, "Ptr", lpPathSpec ; LPSTR in/out
, "Int", nIDListBox ; INT
, "Int", nIDStaticPath ; INT
, "UInt", uFileType ; DLG_DIR_LIST_FILE_TYPE
, "Int") ; return: INT●DlgDirListA(hDlg, lpPathSpec, nIDListBox, nIDStaticPath, uFileType) = DLL("USER32.dll", "int DlgDirListA(void*, char*, int, int, dword)")
# 呼び出し: DlgDirListA(hDlg, lpPathSpec, nIDListBox, nIDStaticPath, uFileType)
# hDlg : HWND -> "void*"
# lpPathSpec : LPSTR in/out -> "char*"
# nIDListBox : INT -> "int"
# nIDStaticPath : INT -> "int"
# uFileType : DLG_DIR_LIST_FILE_TYPE -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "user32" fn DlgDirListA(
hDlg: ?*anyopaque, // HWND
lpPathSpec: [*c]u8, // LPSTR in/out
nIDListBox: i32, // INT
nIDStaticPath: i32, // INT
uFileType: u32 // DLG_DIR_LIST_FILE_TYPE
) callconv(std.os.windows.WINAPI) i32;proc DlgDirListA(
hDlg: pointer, # HWND
lpPathSpec: ptr char, # LPSTR in/out
nIDListBox: int32, # INT
nIDStaticPath: int32, # INT
uFileType: uint32 # DLG_DIR_LIST_FILE_TYPE
): int32 {.importc: "DlgDirListA", stdcall, dynlib: "USER32.dll".}pragma(lib, "user32");
extern(Windows)
int DlgDirListA(
void* hDlg, // HWND
char* lpPathSpec, // LPSTR in/out
int nIDListBox, // INT
int nIDStaticPath, // INT
uint uFileType // DLG_DIR_LIST_FILE_TYPE
);ccall((:DlgDirListA, "USER32.dll"), stdcall, Int32,
(Ptr{Cvoid}, Ptr{UInt8}, Int32, Int32, UInt32),
hDlg, lpPathSpec, nIDListBox, nIDStaticPath, uFileType)
# hDlg : HWND -> Ptr{Cvoid}
# lpPathSpec : LPSTR in/out -> Ptr{UInt8}
# nIDListBox : INT -> Int32
# nIDStaticPath : INT -> Int32
# uFileType : DLG_DIR_LIST_FILE_TYPE -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t DlgDirListA(
void* hDlg,
char* lpPathSpec,
int32_t nIDListBox,
int32_t nIDStaticPath,
uint32_t uFileType);
]]
local user32 = ffi.load("user32")
-- user32.DlgDirListA(hDlg, lpPathSpec, nIDListBox, nIDStaticPath, uFileType)
-- hDlg : HWND
-- lpPathSpec : LPSTR in/out
-- nIDListBox : INT
-- nIDStaticPath : INT
-- uFileType : DLG_DIR_LIST_FILE_TYPE
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('USER32.dll');
const DlgDirListA = lib.func('__stdcall', 'DlgDirListA', 'int32_t', ['void *', 'char *', 'int32_t', 'int32_t', 'uint32_t']);
// DlgDirListA(hDlg, lpPathSpec, nIDListBox, nIDStaticPath, uFileType)
// hDlg : HWND -> 'void *'
// lpPathSpec : LPSTR in/out -> 'char *'
// nIDListBox : INT -> 'int32_t'
// nIDStaticPath : INT -> 'int32_t'
// uFileType : DLG_DIR_LIST_FILE_TYPE -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("USER32.dll", {
DlgDirListA: { parameters: ["pointer", "buffer", "i32", "i32", "u32"], result: "i32" },
});
// lib.symbols.DlgDirListA(hDlg, lpPathSpec, nIDListBox, nIDStaticPath, uFileType)
// hDlg : HWND -> "pointer"
// lpPathSpec : LPSTR in/out -> "buffer"
// nIDListBox : INT -> "i32"
// nIDStaticPath : INT -> "i32"
// uFileType : DLG_DIR_LIST_FILE_TYPE -> "u32"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t DlgDirListA(
void* hDlg,
char* lpPathSpec,
int32_t nIDListBox,
int32_t nIDStaticPath,
uint32_t uFileType);
C, "USER32.dll");
// $ffi->DlgDirListA(hDlg, lpPathSpec, nIDListBox, nIDStaticPath, uFileType);
// hDlg : HWND
// lpPathSpec : LPSTR in/out
// nIDListBox : INT
// nIDStaticPath : INT
// uFileType : DLG_DIR_LIST_FILE_TYPE
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface User32 extends StdCallLibrary {
User32 INSTANCE = Native.load("user32", User32.class, W32APIOptions.ASCII_OPTIONS);
int DlgDirListA(
Pointer hDlg, // HWND
byte[] lpPathSpec, // LPSTR in/out
int nIDListBox, // INT
int nIDStaticPath, // INT
int uFileType // DLG_DIR_LIST_FILE_TYPE
);
}@[Link("user32")]
lib LibUSER32
fun DlgDirListA = DlgDirListA(
hDlg : Void*, # HWND
lpPathSpec : UInt8*, # LPSTR in/out
nIDListBox : Int32, # INT
nIDStaticPath : Int32, # INT
uFileType : UInt32 # DLG_DIR_LIST_FILE_TYPE
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef DlgDirListANative = Int32 Function(Pointer<Void>, Pointer<Utf8>, Int32, Int32, Uint32);
typedef DlgDirListADart = int Function(Pointer<Void>, Pointer<Utf8>, int, int, int);
final DlgDirListA = DynamicLibrary.open('USER32.dll')
.lookupFunction<DlgDirListANative, DlgDirListADart>('DlgDirListA');
// hDlg : HWND -> Pointer<Void>
// lpPathSpec : LPSTR in/out -> Pointer<Utf8>
// nIDListBox : INT -> Int32
// nIDStaticPath : INT -> Int32
// uFileType : DLG_DIR_LIST_FILE_TYPE -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function DlgDirListA(
hDlg: THandle; // HWND
lpPathSpec: PAnsiChar; // LPSTR in/out
nIDListBox: Integer; // INT
nIDStaticPath: Integer; // INT
uFileType: DWORD // DLG_DIR_LIST_FILE_TYPE
): Integer; stdcall;
external 'USER32.dll' name 'DlgDirListA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "DlgDirListA"
c_DlgDirListA :: Ptr () -> CString -> Int32 -> Int32 -> Word32 -> IO Int32
-- hDlg : HWND -> Ptr ()
-- lpPathSpec : LPSTR in/out -> CString
-- nIDListBox : INT -> Int32
-- nIDStaticPath : INT -> Int32
-- uFileType : DLG_DIR_LIST_FILE_TYPE -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let dlgdirlista =
foreign "DlgDirListA"
((ptr void) @-> string @-> int32_t @-> int32_t @-> uint32_t @-> returning int32_t)
(* hDlg : HWND -> (ptr void) *)
(* lpPathSpec : LPSTR in/out -> string *)
(* nIDListBox : INT -> int32_t *)
(* nIDStaticPath : INT -> int32_t *)
(* uFileType : DLG_DIR_LIST_FILE_TYPE -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library user32 (t "USER32.dll"))
(cffi:use-foreign-library user32)
(cffi:defcfun ("DlgDirListA" dlg-dir-list-a :convention :stdcall) :int32
(h-dlg :pointer) ; HWND
(lp-path-spec :pointer) ; LPSTR in/out
(n-idlist-box :int32) ; INT
(n-idstatic-path :int32) ; INT
(u-file-type :uint32)) ; DLG_DIR_LIST_FILE_TYPE
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $DlgDirListA = Win32::API::More->new('USER32',
'int DlgDirListA(HANDLE hDlg, LPSTR lpPathSpec, int nIDListBox, int nIDStaticPath, DWORD uFileType)');
# my $ret = $DlgDirListA->Call($hDlg, $lpPathSpec, $nIDListBox, $nIDStaticPath, $uFileType);
# hDlg : HWND -> HANDLE
# lpPathSpec : LPSTR in/out -> LPSTR
# nIDListBox : INT -> int
# nIDStaticPath : INT -> int
# uFileType : DLG_DIR_LIST_FILE_TYPE -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
- f DlgDirListW (Unicode版) — ディレクトリ内容をダイアログのリストボックスに一覧表示する(Unicode版)。
- f DlgDirListComboBoxA — ディレクトリ内容をダイアログのコンボボックスに一覧表示する(ANSI版)。
- f DlgDirSelectComboBoxExA — コンボボックスで選択中のファイルやディレクトリ名を取得する(ANSI版)。
- f DlgDirSelectExA — リストボックスで選択中のファイルやディレクトリ名を取得する(ANSI版)。