PickIconDlg
関数アイコン選択ダイアログを表示する。
シグネチャ
// SHELL32.dll
#include <windows.h>
INT PickIconDlg(
HWND hwnd, // optional
LPWSTR pszIconPath,
DWORD cchIconPath,
INT* piIconIndex // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hwnd | HWND | inoptional | 親ウィンドウのハンドル。この値は NULL でもかまいません。 |
| pszIconPath | LPWSTR | inout | アイコンを含む既定のリソースの、null で終わる完全修飾パスを格納した文字列へのポインター。ユーザーがダイアログで別のリソースを選択した場合、関数が戻るときにこのバッファにはそのファイルのパスが格納されます。このバッファは少なくとも MAX_PATH 文字の長さが必要です。そうでない場合、返されるパスが切り詰められる可能性があります。使用する前に、パスが有効であることを確認してください。 |
| cchIconPath | DWORD | in | 終端の NULL 文字を含む、pszIconPath の文字数。 |
| piIconIndex | INT* | inoutoptional | 整数へのポインター。入力時には初期選択のインデックスを指定し、この関数が正常に戻ると、選択されたアイコンのインデックスを受け取ります。 |
戻り値の型: INT
公式ドキュメント
PickIconDlg は変更されるか、利用できなくなる可能性があります。
戻り値
型: int
成功した場合は 1 を、それ以外の場合は 0 を返します。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// SHELL32.dll
#include <windows.h>
INT PickIconDlg(
HWND hwnd, // optional
LPWSTR pszIconPath,
DWORD cchIconPath,
INT* piIconIndex // optional
);[DllImport("SHELL32.dll", ExactSpelling = true)]
static extern int PickIconDlg(
IntPtr hwnd, // HWND optional
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszIconPath, // LPWSTR in/out
uint cchIconPath, // DWORD
IntPtr piIconIndex // INT* optional, in/out
);<DllImport("SHELL32.dll", ExactSpelling:=True)>
Public Shared Function PickIconDlg(
hwnd As IntPtr, ' HWND optional
<MarshalAs(UnmanagedType.LPWStr)> pszIconPath As System.Text.StringBuilder, ' LPWSTR in/out
cchIconPath As UInteger, ' DWORD
piIconIndex As IntPtr ' INT* optional, in/out
) As Integer
End Function' hwnd : HWND optional
' pszIconPath : LPWSTR in/out
' cchIconPath : DWORD
' piIconIndex : INT* optional, in/out
Declare PtrSafe Function PickIconDlg Lib "shell32" ( _
ByVal hwnd As LongPtr, _
ByVal pszIconPath As LongPtr, _
ByVal cchIconPath As Long, _
ByVal piIconIndex As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
PickIconDlg = ctypes.windll.shell32.PickIconDlg
PickIconDlg.restype = ctypes.c_int
PickIconDlg.argtypes = [
wintypes.HANDLE, # hwnd : HWND optional
wintypes.LPWSTR, # pszIconPath : LPWSTR in/out
wintypes.DWORD, # cchIconPath : DWORD
ctypes.POINTER(ctypes.c_int), # piIconIndex : INT* optional, in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SHELL32.dll')
PickIconDlg = Fiddle::Function.new(
lib['PickIconDlg'],
[
Fiddle::TYPE_VOIDP, # hwnd : HWND optional
Fiddle::TYPE_VOIDP, # pszIconPath : LPWSTR in/out
-Fiddle::TYPE_INT, # cchIconPath : DWORD
Fiddle::TYPE_VOIDP, # piIconIndex : INT* optional, in/out
],
Fiddle::TYPE_INT)#[link(name = "shell32")]
extern "system" {
fn PickIconDlg(
hwnd: *mut core::ffi::c_void, // HWND optional
pszIconPath: *mut u16, // LPWSTR in/out
cchIconPath: u32, // DWORD
piIconIndex: *mut i32 // INT* optional, in/out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("SHELL32.dll")]
public static extern int PickIconDlg(IntPtr hwnd, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszIconPath, uint cchIconPath, IntPtr piIconIndex);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHELL32_PickIconDlg' -Namespace Win32 -PassThru
# $api::PickIconDlg(hwnd, pszIconPath, cchIconPath, piIconIndex)#uselib "SHELL32.dll"
#func global PickIconDlg "PickIconDlg" sptr, sptr, sptr, sptr
; PickIconDlg hwnd, varptr(pszIconPath), cchIconPath, varptr(piIconIndex) ; 戻り値は stat
; hwnd : HWND optional -> "sptr"
; pszIconPath : LPWSTR in/out -> "sptr"
; cchIconPath : DWORD -> "sptr"
; piIconIndex : INT* optional, in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "SHELL32.dll" #cfunc global PickIconDlg "PickIconDlg" sptr, var, int, var ; res = PickIconDlg(hwnd, pszIconPath, cchIconPath, piIconIndex) ; hwnd : HWND optional -> "sptr" ; pszIconPath : LPWSTR in/out -> "var" ; cchIconPath : DWORD -> "int" ; piIconIndex : INT* optional, in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "SHELL32.dll" #cfunc global PickIconDlg "PickIconDlg" sptr, sptr, int, sptr ; res = PickIconDlg(hwnd, varptr(pszIconPath), cchIconPath, varptr(piIconIndex)) ; hwnd : HWND optional -> "sptr" ; pszIconPath : LPWSTR in/out -> "sptr" ; cchIconPath : DWORD -> "int" ; piIconIndex : INT* optional, in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; INT PickIconDlg(HWND hwnd, LPWSTR pszIconPath, DWORD cchIconPath, INT* piIconIndex) #uselib "SHELL32.dll" #cfunc global PickIconDlg "PickIconDlg" intptr, var, int, var ; res = PickIconDlg(hwnd, pszIconPath, cchIconPath, piIconIndex) ; hwnd : HWND optional -> "intptr" ; pszIconPath : LPWSTR in/out -> "var" ; cchIconPath : DWORD -> "int" ; piIconIndex : INT* optional, in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; INT PickIconDlg(HWND hwnd, LPWSTR pszIconPath, DWORD cchIconPath, INT* piIconIndex) #uselib "SHELL32.dll" #cfunc global PickIconDlg "PickIconDlg" intptr, intptr, int, intptr ; res = PickIconDlg(hwnd, varptr(pszIconPath), cchIconPath, varptr(piIconIndex)) ; hwnd : HWND optional -> "intptr" ; pszIconPath : LPWSTR in/out -> "intptr" ; cchIconPath : DWORD -> "int" ; piIconIndex : INT* optional, in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
shell32 = windows.NewLazySystemDLL("SHELL32.dll")
procPickIconDlg = shell32.NewProc("PickIconDlg")
)
// hwnd (HWND optional), pszIconPath (LPWSTR in/out), cchIconPath (DWORD), piIconIndex (INT* optional, in/out)
r1, _, err := procPickIconDlg.Call(
uintptr(hwnd),
uintptr(pszIconPath),
uintptr(cchIconPath),
uintptr(piIconIndex),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // INTfunction PickIconDlg(
hwnd: THandle; // HWND optional
pszIconPath: PWideChar; // LPWSTR in/out
cchIconPath: DWORD; // DWORD
piIconIndex: Pointer // INT* optional, in/out
): Integer; stdcall;
external 'SHELL32.dll' name 'PickIconDlg';result := DllCall("SHELL32\PickIconDlg"
, "Ptr", hwnd ; HWND optional
, "Ptr", pszIconPath ; LPWSTR in/out
, "UInt", cchIconPath ; DWORD
, "Ptr", piIconIndex ; INT* optional, in/out
, "Int") ; return: INT●PickIconDlg(hwnd, pszIconPath, cchIconPath, piIconIndex) = DLL("SHELL32.dll", "int PickIconDlg(void*, char*, dword, void*)")
# 呼び出し: PickIconDlg(hwnd, pszIconPath, cchIconPath, piIconIndex)
# hwnd : HWND optional -> "void*"
# pszIconPath : LPWSTR in/out -> "char*"
# cchIconPath : DWORD -> "dword"
# piIconIndex : INT* optional, in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "shell32" fn PickIconDlg(
hwnd: ?*anyopaque, // HWND optional
pszIconPath: [*c]u16, // LPWSTR in/out
cchIconPath: u32, // DWORD
piIconIndex: [*c]i32 // INT* optional, in/out
) callconv(std.os.windows.WINAPI) i32;proc PickIconDlg(
hwnd: pointer, # HWND optional
pszIconPath: ptr uint16, # LPWSTR in/out
cchIconPath: uint32, # DWORD
piIconIndex: ptr int32 # INT* optional, in/out
): int32 {.importc: "PickIconDlg", stdcall, dynlib: "SHELL32.dll".}pragma(lib, "shell32");
extern(Windows)
int PickIconDlg(
void* hwnd, // HWND optional
wchar* pszIconPath, // LPWSTR in/out
uint cchIconPath, // DWORD
int* piIconIndex // INT* optional, in/out
);ccall((:PickIconDlg, "SHELL32.dll"), stdcall, Int32,
(Ptr{Cvoid}, Ptr{UInt16}, UInt32, Ptr{Int32}),
hwnd, pszIconPath, cchIconPath, piIconIndex)
# hwnd : HWND optional -> Ptr{Cvoid}
# pszIconPath : LPWSTR in/out -> Ptr{UInt16}
# cchIconPath : DWORD -> UInt32
# piIconIndex : INT* optional, in/out -> Ptr{Int32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t PickIconDlg(
void* hwnd,
uint16_t* pszIconPath,
uint32_t cchIconPath,
int32_t* piIconIndex);
]]
local shell32 = ffi.load("shell32")
-- shell32.PickIconDlg(hwnd, pszIconPath, cchIconPath, piIconIndex)
-- hwnd : HWND optional
-- pszIconPath : LPWSTR in/out
-- cchIconPath : DWORD
-- piIconIndex : INT* optional, in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('SHELL32.dll');
const PickIconDlg = lib.func('__stdcall', 'PickIconDlg', 'int32_t', ['void *', 'uint16_t *', 'uint32_t', 'int32_t *']);
// PickIconDlg(hwnd, pszIconPath, cchIconPath, piIconIndex)
// hwnd : HWND optional -> 'void *'
// pszIconPath : LPWSTR in/out -> 'uint16_t *'
// cchIconPath : DWORD -> 'uint32_t'
// piIconIndex : INT* optional, in/out -> 'int32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("SHELL32.dll", {
PickIconDlg: { parameters: ["pointer", "buffer", "u32", "pointer"], result: "i32" },
});
// lib.symbols.PickIconDlg(hwnd, pszIconPath, cchIconPath, piIconIndex)
// hwnd : HWND optional -> "pointer"
// pszIconPath : LPWSTR in/out -> "buffer"
// cchIconPath : DWORD -> "u32"
// piIconIndex : INT* optional, in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t PickIconDlg(
void* hwnd,
uint16_t* pszIconPath,
uint32_t cchIconPath,
int32_t* piIconIndex);
C, "SHELL32.dll");
// $ffi->PickIconDlg(hwnd, pszIconPath, cchIconPath, piIconIndex);
// hwnd : HWND optional
// pszIconPath : LPWSTR in/out
// cchIconPath : DWORD
// piIconIndex : INT* optional, in/out
// 構造体/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 Shell32 extends StdCallLibrary {
Shell32 INSTANCE = Native.load("shell32", Shell32.class);
int PickIconDlg(
Pointer hwnd, // HWND optional
char[] pszIconPath, // LPWSTR in/out
int cchIconPath, // DWORD
IntByReference piIconIndex // INT* optional, in/out
);
}@[Link("shell32")]
lib LibSHELL32
fun PickIconDlg = PickIconDlg(
hwnd : Void*, # HWND optional
pszIconPath : UInt16*, # LPWSTR in/out
cchIconPath : UInt32, # DWORD
piIconIndex : Int32* # INT* optional, in/out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef PickIconDlgNative = Int32 Function(Pointer<Void>, Pointer<Utf16>, Uint32, Pointer<Int32>);
typedef PickIconDlgDart = int Function(Pointer<Void>, Pointer<Utf16>, int, Pointer<Int32>);
final PickIconDlg = DynamicLibrary.open('SHELL32.dll')
.lookupFunction<PickIconDlgNative, PickIconDlgDart>('PickIconDlg');
// hwnd : HWND optional -> Pointer<Void>
// pszIconPath : LPWSTR in/out -> Pointer<Utf16>
// cchIconPath : DWORD -> Uint32
// piIconIndex : INT* optional, in/out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function PickIconDlg(
hwnd: THandle; // HWND optional
pszIconPath: PWideChar; // LPWSTR in/out
cchIconPath: DWORD; // DWORD
piIconIndex: Pointer // INT* optional, in/out
): Integer; stdcall;
external 'SHELL32.dll' name 'PickIconDlg';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "PickIconDlg"
c_PickIconDlg :: Ptr () -> CWString -> Word32 -> Ptr Int32 -> IO Int32
-- hwnd : HWND optional -> Ptr ()
-- pszIconPath : LPWSTR in/out -> CWString
-- cchIconPath : DWORD -> Word32
-- piIconIndex : INT* optional, in/out -> Ptr Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let pickicondlg =
foreign "PickIconDlg"
((ptr void) @-> (ptr uint16_t) @-> uint32_t @-> (ptr int32_t) @-> returning int32_t)
(* hwnd : HWND optional -> (ptr void) *)
(* pszIconPath : LPWSTR in/out -> (ptr uint16_t) *)
(* cchIconPath : DWORD -> uint32_t *)
(* piIconIndex : INT* optional, in/out -> (ptr int32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library shell32 (t "SHELL32.dll"))
(cffi:use-foreign-library shell32)
(cffi:defcfun ("PickIconDlg" pick-icon-dlg :convention :stdcall) :int32
(hwnd :pointer) ; HWND optional
(psz-icon-path :pointer) ; LPWSTR in/out
(cch-icon-path :uint32) ; DWORD
(pi-icon-index :pointer)) ; INT* optional, in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $PickIconDlg = Win32::API::More->new('SHELL32',
'int PickIconDlg(HANDLE hwnd, LPWSTR pszIconPath, DWORD cchIconPath, LPVOID piIconIndex)');
# my $ret = $PickIconDlg->Call($hwnd, $pszIconPath, $cchIconPath, $piIconIndex);
# hwnd : HWND optional -> HANDLE
# pszIconPath : LPWSTR in/out -> LPWSTR
# cchIconPath : DWORD -> DWORD
# piIconIndex : INT* optional, in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。