SelectFolderDialog with only drives, no folder selection inside drives

走远了吗. 提交于 2019-12-25 02:39:39

问题


In nsis SelectFolderDialog for folder selection window. But i want to appear or user to select only drives.There should not be selection of folders inside a drive. So user should get drives like C: D: E: etc Is there any option to do it?


回答1:


This only allows you to select paths shorter than 4 characters inside My Computer, if you want to hide the folders in the dialog you need to write a plugin and implement IFolderFilter (WinXP+ only)

#BIF_RETURNONLYFSDIRS 0x00000001
#BIF_NEWDIALOGSTYLE 0x00000040
#BIF_NONEWFOLDERBUTTON 0x00000200
!include LogicLib.nsh
!include WinMessages.nsh
!define /math BFFM_ENABLEOK ${WM_USER} + 101
!define BFFM_SELCHANGED 2
System::Call 'SHELL32::SHGetSpecialFolderLocation(i0,i0x11,*i.r2)i.r0'
System::Get "(i.R0,i.R1,i.R2,i)iR9R9"
Pop $3
System::Call '*(i$hwndparent,i$2,i,t "Hello",i0x241,kr3,i0,i0)i.r1'
System::Call 'SHELL32::SHBrowseForFolder(ir1)i.r0'
Sys_BFFCALLBACK:
    ${If} $R9 == "callback1"
        ${If} ${BFFM_SELCHANGED} = $R1
            System::Call 'SHELL32::SHGetPathFromIDList(i$R2,t "" R9)'
            StrLen $R9 $R9
            ${IfThen} $R9 > 3 ${|} StrCpy $R9 0 ${|}
            SendMessage $R0 ${BFFM_ENABLEOK} 0 $R9
        ${EndIf}
        StrCpy $R9 0 ; return value
        System::Call $3
        Goto Sys_BFFCALLBACK
    ${EndIf}
System::Free $3 ; system callback
System::Call 'OLE32::CoTaskMemFree(ir2)' ; BROWSEINFO.pidlRoot
System::Free $1 ; BROWSEINFO
${If} $0 <> 0
    System::Call 'SHELL32::SHGetPathFromIDList(i$0,t "" R9)'
    MessageBox mb_ok SHBrowseForFolder=$R9
${EndIf}
System::Call 'OLE32::CoTaskMemFree(ir0)' ; pidl result


来源:https://stackoverflow.com/questions/19728596/selectfolderdialog-with-only-drives-no-folder-selection-inside-drives

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!