ファイル選択ダイアログボックスを開く
Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" _
(lpofn As OPENFILENAME) As Long
Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" _
(lpofn As OPENFILENAME) As Integer
BOOL GetOpenFileName(
LPOPENFILENAME lpofn
);
引数
lpofn
OPENFILENAME構造体戻り値
OKボタンを押したとき 0以外備考
キャンセル or クローズのとき 0
ファイル選択ダイアログは、Windows95以降はエクスプローラ型が標準なっているがサンプル
Windows3.1のような旧スタイルも表示可能である。
ダウンロード(GetOpenFileName.lzh 3.18KB)Private Sub Command1_Click()
Dim lpofn As OPENFILENAME
With lpofn
.flags = OFN_PATHMUSTEXIST Or OFN_HIDEREADONLY
.lStructSize = Len(lpofn)
.hwndOwner = DialoghWnd
.lpstrFileTitle = String(256, Chr(0))
.nMaxFileTitle = 256
.lpstrFile = String(256, Chr(0))
.nMaxFile = 256
.lpstrTitle = "変数定義ファイルを選択"
.lpstrFilter = "HTML File(*.html)" + Chr(0) + "*.html" + Chr(0) + _
"Text File(*.txt)" + Chr(0) + "*.txt" + Chr(0) + _
"All File(*.*)" + Chr(0) + "*.*"
.lpstrInitialDir = App.Path
.nFilterIndex = 2
rc = GetOpenFileName(lpofn)
If rc > 0 Then
a = InStr(.lpstrFile, Chr(0))
MsgBox Mid(.lpstrFile, 1, a - 1)
End If
End With
End Sub