SHOpenWithDialog
関数プログラムから開くダイアログを表示する。
シグネチャ
// SHELL32.dll
#include <windows.h>
HRESULT SHOpenWithDialog(
HWND hwndParent, // optional
const OPENASINFO* poainfo
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hwndParent | HWND | inoptional | 親ウィンドウのハンドル。この値は NULL にできます。 |
| poainfo | OPENASINFO* | in | OPENASINFO 構造体へのポインター。結果として表示されるダイアログの内容を指定します。 |
戻り値の型: HRESULT
公式ドキュメント
[プログラムから開く] ダイアログ ボックスを表示します。
戻り値
型: HRESULT
この関数が成功した場合は S_OK を返します。それ以外の場合は HRESULT エラー コードを返します。
解説(Remarks)
Windows 10 以降では、OAIF_ALLOW_REGISTRATION、OAIF_FORCE_REGISTRATION、および OAIF_HIDE_REGISTRATION フラグは SHOpenWithDialog によって無視されます。[プログラムから開く] ダイアログ ボックスを使用して、ファイル拡張子を開くために使用される既定のプログラムを変更することはできなくなりました。SHOpenWithDialog は単一のファイルを開くためにのみ使用できます。
OAIF_EXEC を渡さずに SHOpenWithDialog を呼び出した場合、ファイル拡張子を開くために使用される既定のプログラムを 設定 で変更できることを知らせるダイアログがユーザーに表示されます。
出典・ライセンス: 上記「公式ドキュメント」の内容は 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>
HRESULT SHOpenWithDialog(
HWND hwndParent, // optional
const OPENASINFO* poainfo
);[DllImport("SHELL32.dll", ExactSpelling = true)]
static extern int SHOpenWithDialog(
IntPtr hwndParent, // HWND optional
IntPtr poainfo // OPENASINFO*
);<DllImport("SHELL32.dll", ExactSpelling:=True)>
Public Shared Function SHOpenWithDialog(
hwndParent As IntPtr, ' HWND optional
poainfo As IntPtr ' OPENASINFO*
) As Integer
End Function' hwndParent : HWND optional
' poainfo : OPENASINFO*
Declare PtrSafe Function SHOpenWithDialog Lib "shell32" ( _
ByVal hwndParent As LongPtr, _
ByVal poainfo As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SHOpenWithDialog = ctypes.windll.shell32.SHOpenWithDialog
SHOpenWithDialog.restype = ctypes.c_int
SHOpenWithDialog.argtypes = [
wintypes.HANDLE, # hwndParent : HWND optional
ctypes.c_void_p, # poainfo : OPENASINFO*
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SHELL32.dll')
SHOpenWithDialog = Fiddle::Function.new(
lib['SHOpenWithDialog'],
[
Fiddle::TYPE_VOIDP, # hwndParent : HWND optional
Fiddle::TYPE_VOIDP, # poainfo : OPENASINFO*
],
Fiddle::TYPE_INT)#[link(name = "shell32")]
extern "system" {
fn SHOpenWithDialog(
hwndParent: *mut core::ffi::c_void, // HWND optional
poainfo: *const OPENASINFO // OPENASINFO*
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("SHELL32.dll")]
public static extern int SHOpenWithDialog(IntPtr hwndParent, IntPtr poainfo);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHELL32_SHOpenWithDialog' -Namespace Win32 -PassThru
# $api::SHOpenWithDialog(hwndParent, poainfo)#uselib "SHELL32.dll"
#func global SHOpenWithDialog "SHOpenWithDialog" sptr, sptr
; SHOpenWithDialog hwndParent, varptr(poainfo) ; 戻り値は stat
; hwndParent : HWND optional -> "sptr"
; poainfo : OPENASINFO* -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "SHELL32.dll" #cfunc global SHOpenWithDialog "SHOpenWithDialog" sptr, var ; res = SHOpenWithDialog(hwndParent, poainfo) ; hwndParent : HWND optional -> "sptr" ; poainfo : OPENASINFO* -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "SHELL32.dll" #cfunc global SHOpenWithDialog "SHOpenWithDialog" sptr, sptr ; res = SHOpenWithDialog(hwndParent, varptr(poainfo)) ; hwndParent : HWND optional -> "sptr" ; poainfo : OPENASINFO* -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT SHOpenWithDialog(HWND hwndParent, OPENASINFO* poainfo) #uselib "SHELL32.dll" #cfunc global SHOpenWithDialog "SHOpenWithDialog" intptr, var ; res = SHOpenWithDialog(hwndParent, poainfo) ; hwndParent : HWND optional -> "intptr" ; poainfo : OPENASINFO* -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT SHOpenWithDialog(HWND hwndParent, OPENASINFO* poainfo) #uselib "SHELL32.dll" #cfunc global SHOpenWithDialog "SHOpenWithDialog" intptr, intptr ; res = SHOpenWithDialog(hwndParent, varptr(poainfo)) ; hwndParent : HWND optional -> "intptr" ; poainfo : OPENASINFO* -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
shell32 = windows.NewLazySystemDLL("SHELL32.dll")
procSHOpenWithDialog = shell32.NewProc("SHOpenWithDialog")
)
// hwndParent (HWND optional), poainfo (OPENASINFO*)
r1, _, err := procSHOpenWithDialog.Call(
uintptr(hwndParent),
uintptr(poainfo),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction SHOpenWithDialog(
hwndParent: THandle; // HWND optional
poainfo: Pointer // OPENASINFO*
): Integer; stdcall;
external 'SHELL32.dll' name 'SHOpenWithDialog';result := DllCall("SHELL32\SHOpenWithDialog"
, "Ptr", hwndParent ; HWND optional
, "Ptr", poainfo ; OPENASINFO*
, "Int") ; return: HRESULT●SHOpenWithDialog(hwndParent, poainfo) = DLL("SHELL32.dll", "int SHOpenWithDialog(void*, void*)")
# 呼び出し: SHOpenWithDialog(hwndParent, poainfo)
# hwndParent : HWND optional -> "void*"
# poainfo : OPENASINFO* -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "shell32" fn SHOpenWithDialog(
hwndParent: ?*anyopaque, // HWND optional
poainfo: [*c]OPENASINFO // OPENASINFO*
) callconv(std.os.windows.WINAPI) i32;proc SHOpenWithDialog(
hwndParent: pointer, # HWND optional
poainfo: ptr OPENASINFO # OPENASINFO*
): int32 {.importc: "SHOpenWithDialog", stdcall, dynlib: "SHELL32.dll".}pragma(lib, "shell32");
extern(Windows)
int SHOpenWithDialog(
void* hwndParent, // HWND optional
OPENASINFO* poainfo // OPENASINFO*
);ccall((:SHOpenWithDialog, "SHELL32.dll"), stdcall, Int32,
(Ptr{Cvoid}, Ptr{OPENASINFO}),
hwndParent, poainfo)
# hwndParent : HWND optional -> Ptr{Cvoid}
# poainfo : OPENASINFO* -> Ptr{OPENASINFO}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t SHOpenWithDialog(
void* hwndParent,
void* poainfo);
]]
local shell32 = ffi.load("shell32")
-- shell32.SHOpenWithDialog(hwndParent, poainfo)
-- hwndParent : HWND optional
-- poainfo : OPENASINFO*
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('SHELL32.dll');
const SHOpenWithDialog = lib.func('__stdcall', 'SHOpenWithDialog', 'int32_t', ['void *', 'void *']);
// SHOpenWithDialog(hwndParent, poainfo)
// hwndParent : HWND optional -> 'void *'
// poainfo : OPENASINFO* -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("SHELL32.dll", {
SHOpenWithDialog: { parameters: ["pointer", "pointer"], result: "i32" },
});
// lib.symbols.SHOpenWithDialog(hwndParent, poainfo)
// hwndParent : HWND optional -> "pointer"
// poainfo : OPENASINFO* -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t SHOpenWithDialog(
void* hwndParent,
void* poainfo);
C, "SHELL32.dll");
// $ffi->SHOpenWithDialog(hwndParent, poainfo);
// hwndParent : HWND optional
// poainfo : OPENASINFO*
// 構造体/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 SHOpenWithDialog(
Pointer hwndParent, // HWND optional
Pointer poainfo // OPENASINFO*
);
}@[Link("shell32")]
lib LibSHELL32
fun SHOpenWithDialog = SHOpenWithDialog(
hwndParent : Void*, # HWND optional
poainfo : OPENASINFO* # OPENASINFO*
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SHOpenWithDialogNative = Int32 Function(Pointer<Void>, Pointer<Void>);
typedef SHOpenWithDialogDart = int Function(Pointer<Void>, Pointer<Void>);
final SHOpenWithDialog = DynamicLibrary.open('SHELL32.dll')
.lookupFunction<SHOpenWithDialogNative, SHOpenWithDialogDart>('SHOpenWithDialog');
// hwndParent : HWND optional -> Pointer<Void>
// poainfo : OPENASINFO* -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SHOpenWithDialog(
hwndParent: THandle; // HWND optional
poainfo: Pointer // OPENASINFO*
): Integer; stdcall;
external 'SHELL32.dll' name 'SHOpenWithDialog';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SHOpenWithDialog"
c_SHOpenWithDialog :: Ptr () -> Ptr () -> IO Int32
-- hwndParent : HWND optional -> Ptr ()
-- poainfo : OPENASINFO* -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let shopenwithdialog =
foreign "SHOpenWithDialog"
((ptr void) @-> (ptr void) @-> returning int32_t)
(* hwndParent : HWND optional -> (ptr void) *)
(* poainfo : OPENASINFO* -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library shell32 (t "SHELL32.dll"))
(cffi:use-foreign-library shell32)
(cffi:defcfun ("SHOpenWithDialog" shopen-with-dialog :convention :stdcall) :int32
(hwnd-parent :pointer) ; HWND optional
(poainfo :pointer)) ; OPENASINFO*
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SHOpenWithDialog = Win32::API::More->new('SHELL32',
'int SHOpenWithDialog(HANDLE hwndParent, LPVOID poainfo)');
# my $ret = $SHOpenWithDialog->Call($hwndParent, $poainfo);
# hwndParent : HWND optional -> HANDLE
# poainfo : OPENASINFO* -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
使用する型