Jump to content
Sign in to follow this  
GordonFreeman

Force FileOpenDialog to show "init dir" always

Recommended Posts

The Function FileOpenDialog only show init dir when i not select a file, when i select a file the folder of this file is the init dir. Theres an way to force FileOpenDialog to "respect" always the "Init Dir" parameter?

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListBox.au3>
#include <Array.au3>
#include <File.au3>


$hGUI = GUICreate("Form1",500,500,-1,-1)

$hBtnGet = GUICtrlCreateButton("Test",400,400,100,25)

GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hBtnGet
            $File = FileOpenDialog("Selecione um Arquivo",@ScriptDir,"All (*.*)",1)
            FileChangeDir(@ScriptDir)
            MsgBox(0,"",$File)

    EndSwitch
WEnd

Share this post


Link to post
Share on other sites

You need to use a fixed path not a macro and it will work.  You can make it a relative path to your script - try that.  Because the successful return changes the @workingdir

 

@WorkingDir is changed on successful return. - the help file

Edited by Jfish

Share this post


Link to post
Share on other sites

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$hGUI = GUICreate("Form1", 100, 100, -1, -1)
$hBtnGet = GUICtrlCreateButton("Test", 10, 35, 80, 25)
GUISetState(@SW_SHOW)

Global $sInitDir = @ScriptDir

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $hBtnGet

            ; http://msdn.microsoft.com/en-us/library/windows/desktop/ms646839%28v=vs.85%29.aspx
            ; OPENFILENAME structure
            ; lpstrInitialDir
            ; Windows 7: If lpstrInitialDir has the same value as was passed the first time the application used an Open or Save As dialog box, the path most recently selected by the user is used as the initial directory.

            If StringRight($sInitDir, 1) = "\" Then
                $sInitDir = StringTrimRight($sInitDir, 1)
            Else
                $sInitDir &= "\"
            EndIf
            ConsoleWrite($sInitDir & @CRLF)

            $File = FileOpenDialog("Selecione um Arquivo", $sInitDir, "All (*.*)", 1)
            
            MsgBox(0, "", $File)
            
    EndSwitch
WEnd
Edited by KaFu

Share this post


Link to post
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
Sign in to follow this  

×
×
  • Create New...