Results 1 to 3 of 3

Thread: Open Dialog Path = Computer?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2001
    Location
    MN
    Posts
    362

    Open Dialog Path = Computer?

    I have a Open Dialog (using CommonDialog). I'd like the path of the dialog to be the path of the computer, like in the pic below.

    Name:  Clipboard01.jpg
Views: 240
Size:  39.3 KB

    I've tried CommonDialog3.InitDir = Computer, but that opens the Desktop path.......

  2. #2
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,647

    Re: Open Dialog Path = Computer?

    I don't believe the legacy common dialogs even support opening locations that aren't normal file system paths. Setting it to the GUID, ::{20d04fe0-3aea-1069-a2d8-08002b30309d}, doesn't work either.

    If you need to retain support for XP, you don't really have an option short of rolling your own, but if you can live with Vista+, you should use the new common dialogs, IFileOpenDialog / IFileSaveDialog. Those allow you to set the initial folder to all special locations, among many many other new features.

    In a project with my modern shell interface TLB and IID module, it goes like this:
    Code:
    Dim psiInitDir As IShellItem
    Dim pFOD As New FileOpenDialog
    Dim psiResult As IShellItem
    Dim lpRes As Long, sResult As String
    Call SHGetKnownFolderItem(FOLDERID_ComputerFolder, KF_FLAG_DEFAULT, 0&, IID_IShellItem, psiInitDir)
    pFOD.SetFolder psiInitDir '.SetDefaultFolder is ignored in favor of the last-opened path; .SetFolder forces it every time
    '[...set other options if desired, but will work without anything else...]
    pFOD.Show Me.hwnd
    pFOD.GetResult psiResult
    If (psiResult Is Nothing) = False Then
        psiResult.GetDisplayName SIGDN_FILESYSPATH, lpRes
        SysReAllocString VarPtr(sResult), lpRes
        Call CoTaskMemFree(lpRes)
        Debug.Print sResult
    End If
    
    '---------
    'APIs:
    Public Declare Function SHGetKnownFolderItem Lib "shell32" (rfid As UUID, ByVal dwFlags As KNOWN_FOLDER_FLAG, ByVal hToken As Long, riid As UUID, ppv As Any) As Long
    Public Declare Function SysReAllocString Lib "oleaut32.dll" (ByVal pBSTR As Long, Optional ByVal pszStrPtr As Long) As Long
    Public Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal PV As Long) ' Frees memory allocated by the shell
    Last edited by fafalone; Nov 23rd, 2016 at 05:49 PM.

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Open Dialog Path = Computer?

    there was a thread on this recently, by dragokas, on testing, in XP the dialog (api version) would open at my computer, though the display was a bit different to above, but for later versions of windows it would not open at my computer

    maybe you can run version dependent code, of dialog and fafalone's code above
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width