Jump to content

Recommended Posts

Posted

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
Posted (edited)

The initial dir is @scriptdir = D: Then i selected a file in D:Music. When i close and click again the init dir will be D:Music instead of D:. And i can re-run script and will happens the same think

Thanks for attention

Edited by GordonFreeman
Posted (edited)

#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

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
  • Recently Browsing   0 members

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