Sign in to follow this  
Followers 0
jlundqui

Windows "Open" dialog

4 posts in this topic

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

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

Share this post


Link to post
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 !

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  
Followers 0