アプリ版:「スタンプのみでお礼する」機能のリリースについて

VB6.0で、ファイル選択のWinAPI:GetOpenFileNameを使って、利用者に指定させた
ディレクトリー情報("c:\temp"等のホルダー情報)を取得したいのですが、うまくいきません。

このAPIは、ファイルの選択しかできないのでしょうか?
ディレクトリー情報を取得するには、他のWinAPI関数があるのでしょうか?

お教え下さい。

A 回答 (1件)

こんにちは。

maruru01です。

フォルダ選択のAPI
SHBrowseForFolder
を使用します。
フォルダ名を返す関数を参考までに。

標準モジュールに、

Public Type BROWSEINFO
  hwndOwner As Long
  pidlRoot As Long
  pszDisplayName As String
  lpszTitle As String
  ulFlags As Long
  lpfn As Long
  lParam As Long
  iImage As Long
End Type

Public Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BROWSEINFO) As Long

Public Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pIDL As Long, ByVal pszPath As String) As Long

'API使用のフォルダー指定ダイアログ
'Msg:ダイアログのタイトル
'Frm:使用するフォーム(通常はMeを指定)
Public Function GetFolder(Msg As String, Frm As Form) As String

  Const MAX_PATH = 260
  Dim lngRetValue As Long
  Dim strBuffer As String * MAX_PATH
  Dim strPathBuffer As String * MAX_PATH
  Dim udtBrowseInfo As BROWSEINFO
  Dim ReturnPath As String
  Dim rt As String

  strBuffer = String(Len(strBuffer), vbNullChar)
  strBuffer = App.Path & vbNullChar

  If Msg = "" Then
    Msg = "フォルダーを指定してください。"
  End If

  With udtBrowseInfo
    .hwndOwner = Frm.hWnd
    .pidlRoot = &H0
    .pszDisplayName = strBuffer
    .lpszTitle = Msg & vbNullChar
    .ulFlags = &H1
    .lpfn = 0
    .lParam = 0
    .iImage = 0
  End With

  lngRetValue = SHBrowseForFolder(udtBrowseInfo)
  If lngRetValue <> 0& Then
    lngRetValue = SHGetPathFromIDList(lngRetValue, strPathBuffer)
    If lngRetValue = 0 Then
      rt = ""
    Else
      ReturnPath = Left(strPathBuffer, InStr(strPathBuffer, vbNullChar) - 1)
      rt = ReturnPath
    End If
  Else
    rt = ""
  End If
  GetFolder = rt

End Function
    • good
    • 0
この回答へのお礼

ありがとうございました。お蔭様で、解決致しました。

お礼日時:2002/02/06 16:58

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!