Sign in to follow this  
Followers 0
CyberSlug

Win 3.1 style FileOpenDialog

1 post in this topic

Try it out :huh2:

- You might have to triple-click the folder in the list before it changes

- Wildcards in the filename inputbox are not supported

- The label showing the full path gets truncated without showing an ellipsis

- There might be other issues. I was just playing around with GuiSendMsg(...,LB_DIR,...)

- Don't complain about lack of comments or descriptive control names :D

#cs - ### Generated by AutoBuilder 0.4 -- do not modify ###
400 235
0   2   0   1   0   0   0   0   1   4   2   0   0   0   0   0   
input   $input_1    *.* 10  30  130 20  0   0   
list    $list_1 list 1  10  60  130 120 0   0   
list    $list_2 list 2  160 60  140 110 0   0   
combo   $combo_1    Combo 1 160 200 140 70  0   0   
button  $button_1   OK  310 10  80  30  0   0   
button  $button_2   Cancel  310 50  80  30  0   0   
label   $label_1    File &name: 10  10  130 20  0   0   
label   $label_2    &Folders:   160 10  130 20  0   0   
label   $label_3    C:\ 160 30  130 15  0   0   
label   $label_4    Dri&ves:    160 180 130 20  0   0   
#ce - ### End of Dump ###

;Script generated by AutoBuilder 0.4 -- but modified

Global $listboxStyle = BitOr(BitOr(0x200000, 0x1000), 0x1);WS_VSCROLL + $LBS_DISABLENOSCROLL + LBS_NOTIFY
Global $LB_ERR = (-1);

Dim $selDrive = "c:"
Dim $selFolder = "";folder currently selected
Dim $selFile = ""

Dim $chosenFolder = "";if a selected folder is clicked on, it become chosen
Dim $fullFolderPath = "";full path (without drive) such as Windows\System32\Drivers

Opt("GUINotifyMode", 1)
$handle = GuiCreate("Open", 398,230,(@DesktopWidth-398)/2, (@DesktopHeight-230)/2)

$label_1 = GUISetControl("label", "File &name:", 10, 10, 130, 20)
$input_1 = GUISetControl("input", "*.*", 10, 30, 130, 20)
GUISetControlEx($input_1, 256);$GUI_FOCUS
$list_1 = GUISetControl("list", "", 10, 60, 130, 120, $listboxStyle)

$label_2 = GUISetControl("label", "&Folders:", 160, 10, 130, 20)
$label_3 = GUISetControl("label", "C:\", 160, 30, 130, 15)
$list_2 = GUISetControl("list", "", 160, 60, 140, 110, $listboxStyle)

$label_4 = GUISetControl("label", "Dri&ves:", 160, 180, 130, 20)
$combo_1 = GUISetControl("combo", "Combo 1", 160, 200, 140, 70)

$button_1 = GUISetControl("button", "OK", 310, 10, 80, 30)
GUISetControlEx($button_1, 512);$GUI_DEFBUTTON
$button_2 = GUISetControl("button", "Cancel", 310, 50, 80, 30)

populateDrives()
GuiShow()

While 1
    sleep(10)
    $msg = GuiMsg(0)
    Select
    Case $msg = -3
      Exit

    Case $msg = $input_1
     ;;;
        
    Case $msg = $list_1
      $selFile = GuiRead($list_1)
      GuiWrite($input_1, -1, $selFile)
         
    Case $msg = $list_2
     ;simulate double click by treating a click on an already selected item as a major event
     ;remove brackets from the selected item
      Local $item = GuiRead($list_2)
      If StringLeft($item,1) <> '[' Or StringRight($item,1) <> ']' Then ContinueLoop
     ; the bracket check is in case a system file that is not a directory accidently appears in the file list....
      $item = StringTrimLeft(StringTrimRight( $item, 1),1)
   
      If $selFolder <> $item Then
         $selFolder = $item
         ContinueLoop
      EndIf
   
      If $selFolder = $item Then
         If $item = ".." Then;go up one directory
            $chosenFolder = $item
            $fullFolderPath = StringLeft( $fullFolderPath , StringInStr($fullFolderPath,"\",0,-1) - 1 )
         Else;one level deeper
            $chosenFolder = $item
            $fullFolderPath = $fullFolderPath & "\" & $item
         EndIf
      EndIf
   
      populateFolders()
   
    Case $msg = $combo_1
      $selDrive = StringRight( GuiRead($combo_1) , 2);strip "fixed" or "CDROM" from the name
      populateFolders()
        
    Case $msg = $button_1
     ;;;GUIDelete()
      Local $chosen = StringUpper($selDrive) & $fullFolderPath & "\" & $selFile
      MsgBox(4096,"Selected:", $chosen)
     ;;;Exit
      
    Case $msg = $button_2
        ExitLoop
    EndSelect
WEnd
Exit


Func populateDrives()
   Local $i, $list, $device = DriveGetDrive("all")
  ; I'll assume DriveGetDrive never fails
   For $i = 1 to UBound($device)-1
      $list = $list & StringUpper(DriveGetType($device[$i])) & "   " & $device[$i] & "|"
   Next
   GUISetControlData($combo_1, $list, "FIXED   c:")
   
   populateFolders()
EndFunc


Func populateFolders()
  ; attempt to fill list_2 with all folders in the current directory
   Local $workingBak = @WorkingDir
   $absolutePath = $selDrive & $fullFolderPath
   GuiWrite($label_3, -1, StringUpper($selDrive) & $fullFolderPath)
   FileChangeDir($absolutePath)
   $attrib = BitOr(BitOr(0x8000,0x10),0x4);DDL_EXCLUSIVE + DDL_DIRECTORY + DLL_SYSTEM
   GuiSetControlData($list_2, "");clear list
   Local $list = GuiSendMsg($list_2, 0x18D, $attrib, "*.*");LB_DIR
   FileChangeDir($workingBak)
   
   populateFiles()
EndFunc

Func populateFiles()
  ; fill list_1 with the files in the currently selected directory
   Local $workingBak = @WorkingDir
   $absolutePath = $selDrive & $fullFolderPath
   GuiWrite($label_3, -1, StringUpper($selDrive) & $fullFolderPath)
   FileChangeDir($absolutePath)
   GuiSetControlData($list_1, "");clear list
   Local $list = GuiSendMsg($list_1, 0x18D, 0, "*.*");LB_DIR
   FileChangeDir($workingBak)
EndFunc

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

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