Jump to content

Windows "Open" dialog


Recommended Posts

I'd like to open a Windows Open dialog to enter a filename/path in an input box. I'm sure someone has done this already, but I haven't had much luck with searching the Forum. Any help I could get would be much appreciated!

Thanks,

Jen

Link to comment
Share on other sites

Presuming you have a $GUI defined already:

$Btn_Target = GUICtrlCreateButton("Target:", 8, 40, 73, 25, 0)
GUICtrlSetTip(-1, " Select Target File ")
$Txt_Target = GUICtrlCreateInput("", 88, 40, 537, 21)

GUISetState(@SW_SHOW)
While 1
    $msg = GUIGetMsg() ;
    Switch $msg
    Case $GUI_EVENT_CLOSE
         ExitLoop
    Case $Btn_Target
         $target = FileOpenDialog ( "Select a File", , @WindowsDir & "\", "Images (*.jpg;*.bmp)", 1 + 4 )
         if StringLen($target) > 0 Then GUICtrlSetData($Txt_Target, $target)
  EndSwitch
WEnd

Check the help file for 'FileOpenDialog' to learn about more options.

I'd like to open a Windows Open dialog to enter a filename/path in an input box. I'm sure someone has done this already, but I haven't had much luck with searching the Forum. Any help I could get would be much appreciated!

Thanks,

Jen

Edited by DaRam
Link to comment
Share on other sites

I've looked at the functions list too many times, and missed that function entirely. Doh!

Also, the code was incomplete. A corrected version is below:

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

Local $target

$controlwindow = GUICreate("Control", 600, 400, 600, 500)

$Btn_Target = GUICtrlCreateButton("Target:", 8, 40, 73, 25, 0)
GUICtrlSetTip(-1, " Select Target Folder ")
$Txt_Target = GUICtrlCreateInput("", 88, 40, 350, 21)

GUISetState(@SW_SHOW)
While 1
    $msg = GUIGetMsg() ;
    Switch $msg
    Case $Txt_target
         $target = GUICtrlRead($Txt_Target, 1)
    Case $GUI_EVENT_CLOSE
         ExitLoop
     Case $Btn_Target
        $target = FileSelectFolder("Choose Target Folder", "", 1, $target)
    EndSwitch
    if StringLen($target) > 0 Then 
        GUICtrlSetData($Txt_Target, $target & "\")
    EndIf
WEnd

Thanks!

Jen

Edited by jlundqui
Link to comment
Share on other sites

I've looked at the functions list too many times, and missed that function entirely. Doh!

Also, the code was incomplete. A corrected version is below:

I did mention that I presumed you have your GUI setup.

Anyway. I would not move this out of the Switch-EndSwitch code segment:

if StringLen($target) > 0 Then 
        GUICtrlSetData($Txt_Target, $target & "\")
    EndIf
The reason is, that it endlessly will update your Input text box !
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...