Jump to content

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
Link to comment
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

Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Link to comment
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
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...