Jump to content

FileSelectFolder - Windows 7 and later new window type


ALIENQuake
 Share

Recommended Posts

Hello,

When one of the tool that I use ask me to select specific directory, it popups "Browse For Folder" window, which looks like this:

gm69.png

but in Windows 7 there is another window type, which looks like this:

pjcf.png

Is there any way to use this new window type instead of old one?

Link to comment
Share on other sites

Well, I gave it a go. You need someone who actually understands interfaces and objects.

Global Const $FOS_OVERWRITEPROMPT = 0x00000002
Global Const $FOS_STRICTFILETYPES = 0x00000004
Global Const $FOS_NOCHANGEDIR = 0x00000008
Global Const $FOS_PICKFOLDERS = 0x00000020
Global Const $FOS_FORCEFILESYSTEM = 0x00000040
Global Const $FOS_ALLNONSTORAGEITEMS = 0x00000080
Global Const $FOS_NOVALIDATE = 0x00000100
Global Const $FOS_ALLOWMULTISELECT = 0x00000200
Global Const $FOS_PATHMUSTEXIST = 0x00000800
Global Const $FOS_FILEMUSTEXIST = 0x00001000
Global Const $FOS_CREATEPROMPT = 0x00002000
Global Const $FOS_SHAREAWARE = 0x00004000
Global Const $FOS_NOREADONLYRETURN = 0x00008000
Global Const $FOS_NOTESTFILECREATE = 0x00010000
Global Const $FOS_HIDEMRUPLACES = 0x00020000
Global Const $FOS_HIDEPINNEDPLACES = 0x00040000
Global Const $FOS_NODEREFERENCELINKS = 0x00100000
Global Const $FOS_DONTADDTORECENT = 0x02000000
Global Const $FOS_FORCESHOWHIDDEN = 0x10000000
Global Const $FOS_DEFAULTNOMINIMODE = 0x20000000
Global Const $FOS_FORCEPREVIEWPANEON = 0x40000000


_FileSelectFolderNew()
MsgBox(0, @error, @extended)



Func _FileSelectFolderNew($sTitle = "Select Folder", $sRootDir = @DesktopDir, $sInitialDir = @WorkingDir, $hParent = 0)
    Local Const $IID_IModalWindow = "{b4db1657-70d7-485e-8e3e-6fcb5a5c1802}"
    Local Const $TAG_IModalWindow = "hresult Show(hwnd);"

    Local Const $CLSID_IFileDialog = "{42F85136-DB7E-439C-85F1-E4075D135FC8}"
    Local Const $IID_IFileDialog = $CLSID_IFileDialog
    Local const $TAG_IFileDialog = $TAG_IModalWindow & "AddPlace hresult(ptr;int);Advise hresult(ptr;dword*);ClearClientData hresult();" & _
            "Close hresult(hresult);GetCurrentSelection hresult(ptr);GetFileName hresult(ptr);GetFileTypeIndex hresult(uint*);" & _
            "GetFolder hresult(ptr);GetOptions hresult(uint*);GetResult hresult(ptr);SetClientGuid hresult(ptr);" & _
            "SetDefaultExtension hresult(wstr);SetDefaultFolder hresult(ptr);SetFileName hresult(wstr);SetFileNameLabel hresult(wstr);" & _
            "SetFileTypeIndex hresult(uint);SetFileTypes hresult(uint;ptr);SetFilter hresult(ptr);SetFolder hresult(ptr);" & _
            "SetOkButtonLabel hresult(wstr);SetOptions hresult(uint);SetTitle hresult(wstr);Unadvise hresult(dword);"

    Local Const $CLSID_IFileOpenDialog = "{D57C7288-D4AD-4768-BE02-9D969532D960}"
    Local Const $IID_IFileOpenDialog = $CLSID_IFileOpenDialog
    Local Const $TAG_IFileOpenDialog = $TAG_IFileDialog & "GetResults hresult(ptr);GetSelectedItems hresult(ptr);"


    Local $ifd = ObjCreateInterface($CLSID_IFileOpenDialog, $IID_IFileOpenDialog, $TAG_IFileOpenDialog, True)
    If @error Then Return SetError(@error, @extended, "")

    Local $options
    $ifd.GetOptions($options)

    ConsoleWrite($options & @LF)

    $ifd.SetOptions(BitOR($FOS_PICKFOLDERS, $options))

    $ifd.Show(0)
EndFunc

I've got no idea how to find out what the v table order is, so I just did it on alphabetical. I have no idea what an IID is, but the helpfile example has it the same as the CLSID so I did the same.

Link to comment
Share on other sites

  • 2 months later...

Well for another project I learnt a little bit more about objects and interfaces. Turns out there were quite a few mistakes, and I now know about vtable order as well.

I got the dialog to show. Will be a bit more work with interfaces to get the whole IShellItem stuff working, but it's possible anyway.

Global Const $FOS_OVERWRITEPROMPT = 0x00000002
Global Const $FOS_STRICTFILETYPES = 0x00000004
Global Const $FOS_NOCHANGEDIR = 0x00000008
Global Const $FOS_PICKFOLDERS = 0x00000020
Global Const $FOS_FORCEFILESYSTEM = 0x00000040
Global Const $FOS_ALLNONSTORAGEITEMS = 0x00000080
Global Const $FOS_NOVALIDATE = 0x00000100
Global Const $FOS_ALLOWMULTISELECT = 0x00000200
Global Const $FOS_PATHMUSTEXIST = 0x00000800
Global Const $FOS_FILEMUSTEXIST = 0x00001000
Global Const $FOS_CREATEPROMPT = 0x00002000
Global Const $FOS_SHAREAWARE = 0x00004000
Global Const $FOS_NOREADONLYRETURN = 0x00008000
Global Const $FOS_NOTESTFILECREATE = 0x00010000
Global Const $FOS_HIDEMRUPLACES = 0x00020000
Global Const $FOS_HIDEPINNEDPLACES = 0x00040000
Global Const $FOS_NODEREFERENCELINKS = 0x00100000
Global Const $FOS_DONTADDTORECENT = 0x02000000
Global Const $FOS_FORCESHOWHIDDEN = 0x10000000
Global Const $FOS_DEFAULTNOMINIMODE = 0x20000000
Global Const $FOS_FORCEPREVIEWPANEON = 0x40000000


_FileSelectFolderNew()



Func _FileSelectFolderNew($sTitle = "Select Folder", $sRootDir = @DesktopDir, $sInitialDir = @WorkingDir, $hParent = 0)
    Local Const $IID_IModalWindow = "{B4DB1657-70D7-485E-8E3E-6FCB5A5C1802}"
    Local Const $TAG_IModalWindow = "Show hresult(hwnd);"

    Local Const $IID_IFileDialog = "{42F85136-DB7E-439C-85F1-E4075D135FC8}"
    Local Const $TAG_IFileDialog = $TAG_IModalWindow & _
            "SetFileTypes hresult(uint;ptr);" & _
            "SetFileTypeIndex hresult(uint);" & _
            "GetFileTypeIndex hresult(uint*);" & _
            "Advise hresult(ptr;dword*);" & _
            "Unadvise hresult(dword);" & _
            "SetOptions hresult(dword);" & _
            "GetOptions hresult(dword*);" & _
            "SetDefaultFolder hresult(ptr);" & _
            "SetFolder hresult(ptr);" & _
            "GetFolder hresult(ptr);" & _
            "GetCurrentSelection hresult(ptr);" & _
            "SetFileName hresult(wstr);" & _
            "GetFileName hresult(ptr);" & _
            "SetTitle hresult(wstr);" & _
            "SetOkButtonLabel hresult(wstr);" & _
            "SetFileNameLabel hresult(wstr);" & _
            "GetResult hresult(ptr);" & _
            "AddPlace hresult(ptr;int);" & _
            "SetDefaultExtension hresult(wstr);" & _
            "Close hresult(hresult);" & _
            "SetClientGuid hresult(ptr);" & _
            "ClearClientData hresult();" & _
            "SetFilter hresult(ptr);"

    Local Const $CLSID_IFileOpenDialog = "{DC1C5A9C-E88A-4dde-A5A1-60F82A20AEF7}"
    Local Const $IID_IFileOpenDialog = $IID_IFileDialog
    Local Const $TAG_IFileOpenDialog = $TAG_IFileDialog & "GetResults hresult(ptr);GetSelectedItems hresult(ptr);"


    Local $ifd = ObjCreateInterface($CLSID_IFileOpenDialog, $IID_IFileOpenDialog, $TAG_IFileOpenDialog)
    If @error Then Return SetError(@error, @extended, "")

    $ifd.SetTitle("Select Folder...")

    Local $options
    $ifd.GetOptions($options)
    $ifd.SetOptions(BitOR($FOS_PICKFOLDERS, $options))

    $ifd.Show(0)
EndFunc   ;==>_FileSelectFolderNew
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...