C# と VB.NET の質問掲示板

わんくま同盟

ASP.NET、C++/CLI、Java 何でもどうぞ

C# と VB.NET の入門サイト

■103007 / 2階層)  フォルダ選択ダイアログで初期パス指定について
□投稿者/ くま (25回)-(2024/03/13(Wed) 07:27:42)
2024/03/13(Wed) 07:37:35 編集(投稿者)
No103003 (くま さん) に返信
自己解決できましたので解決とします。
修正箇所は以下の通り

Private Function BrowseCallbackProc(ByVal hwnd As LongPtr, ByVal uMsg As Long, ByVal lParam As LongPtr, ByVal lpData As LongPtr) As Long
    Dim strPath         As String
    Dim strClassName    As String
    Dim strWindowName   As String
    
    Dim hWndChild       As LongPtr
    Dim hWndTreeView    As LongPtr

    Const MY_COMPUTER_FOLDER    As String = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"

    If FolderDialog_Step < 9 Then
        Select Case uMsg
            Case BFFM_INITIALIZED
                '----- 一つ上のフォルダを選択
                If FolderDialog_Step = 0 And Len(FolderDialog_UpPath) > 0 Then
                    strPath = MY_COMPUTER_FOLDER
                    If Len(FolderDialog_UpPath) > 0 Then
                        strPath = strPath & "\" & FolderDialog_UpPath
                    End If
                    Call SendMessage(hwnd, BFFM_SETSELECTIONW, True, ByVal StrPtr(strPath))
                    FolderDialog_Step = 1    '処理待機1
                Else
                    FolderDialog_Step = 9    '処理終了
                End If
            
            Case BFFM_SELCHANGED
                If FolderDialog_Step = 2 Then   '処理待機2
                    '----- 選択されたパス取得
                    strPath = String(MAX_PATH * 2, vbNullChar)
                    Call SHGetPathFromIDList(lParam, StrPtr(strPath))
                    strPath = Left(strPath, InStr(strPath, vbNullChar & vbNullChar) - 1)

                    '----- 指定されたパスが選択されている場合
                    If strPath = FolderDialog_UpPath Then
                        '----- フォルダを選択ダイアログのコントロール取得
                        strClassName = "SHBrowseForFolder ShellNameSpace Control"
                        strWindowName = vbNullString
                        hWndChild = FindWindowEx(hwnd, 0, StrPtr(strClassName), StrPtr(strWindowName))

                        If hWndChild <> 0 Then
                            '----- フォルダを選択ダイアログのツリービュー取得
                            strClassName = "SysTreeView32"
                            strWindowName = vbNullString
                            hWndTreeView = FindWindowEx(hWndChild, 0, StrPtr(strClassName), StrPtr(strWindowName))

                            If hWndChild <> 0 Then
                                '----- テンキー[+]を送信(ツリー展開)
                                Call SendMessage(hWndTreeView, WM_KEYDOWN, VK_ADD, 0)
                                Call SendMessage(hWndTreeView, WM_KEYUP, VK_ADD, 0)

                                '----- フォルダを選択
                                If FolderDialog_UpPath <> FolderDialog_Path _
                                And Len(FolderDialog_Path) > 0 Then
                                    strPath = MY_COMPUTER_FOLDER
                                    If Len(FolderDialog_Path) > 0 Then
                                        strPath = strPath & "\" & FolderDialog_Path
                                    End If
                                    Call SendMessage(hwnd, BFFM_SETSELECTIONW, True, ByVal StrPtr(strPath))
'                                    Call SendMessage(hwnd, BFFM_SETSELECTIONW, True, ByVal StrPtr(FolderDialog_Path))
                                End If
                            End If
                        End If
                        FolderDialog_Step = 9    '処理終了
                    End If
                End If
            
            Case BFFM_VALIDATEFAILEDA
            Case BFFM_VALIDATEFAILEDW
            Case BFFM_IUNKNOWN
                If FolderDialog_Step < 2 Then FolderDialog_Step = 2   '処理待機2
        End Select
    End If
End Function


解決済み
編集キー/

前の記事(元になった記事) 次の記事(この記事の返信)
←Re[1]: フォルダ選択ダイアログで初期パス指定について /くま 返信無し
 
上記関連ツリー

フォルダ選択ダイアログで初期パス指定について / くま (24/03/11(Mon) 12:33) #103002
Re[1]: フォルダ選択ダイアログで初期パス指定について / くま (24/03/11(Mon) 12:34) #103003
  └ フォルダ選択ダイアログで初期パス指定について / くま (24/03/13(Wed) 07:27) #103007 解決済み ←Now

上記ツリーを一括表示 / 上記ツリーをトピック表示
 
上記の記事へ返信