home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / vbdb / gfilebox.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-09-06  |  9.0 KB  |  300 lines

  1. VERSION 2.00
  2. Begin Form GetFileBox 
  3.    BorderStyle     =   3  'Fixed Double
  4.    ClientHeight    =   2640
  5.    ClientLeft      =   1725
  6.    ClientTop       =   2445
  7.    ClientWidth     =   5055
  8.    Height          =   3045
  9.    Left            =   1665
  10.    LinkMode        =   1  'Source
  11.    LinkTopic       =   "Form1"
  12.    MaxButton       =   0   'False
  13.    MinButton       =   0   'False
  14.    ScaleHeight     =   2640
  15.    ScaleWidth      =   5055
  16.    Top             =   2100
  17.    Width           =   5175
  18.    Begin ListBox Dirs 
  19.       Height          =   1200
  20.       Left            =   1848
  21.       Sorted          =   -1  'True
  22.       TabIndex        =   4
  23.       Top             =   1260
  24.       Width           =   1530
  25.    End
  26.    Begin ListBox Files 
  27.       Height          =   1590
  28.       Left            =   168
  29.       Sorted          =   -1  'True
  30.       TabIndex        =   3
  31.       Top             =   912
  32.       Width           =   1530
  33.    End
  34.    Begin CommandButton Command2 
  35.       Caption         =   "Cancel"
  36.       Height          =   348
  37.       Left            =   3948
  38.       TabIndex        =   6
  39.       Top             =   600
  40.       Width           =   936
  41.    End
  42.    Begin CommandButton Command1 
  43.       Caption         =   "OK"
  44.       Height          =   348
  45.       Left            =   3948
  46.       TabIndex        =   5
  47.       Top             =   120
  48.       Width           =   936
  49.    End
  50.    Begin TextBox FileSpec 
  51.       Height          =   288
  52.       Left            =   1176
  53.       TabIndex        =   2
  54.       Top             =   132
  55.       Width           =   2616
  56.    End
  57.    Begin Label Label2 
  58.       Caption         =   "&Directories:"
  59.       Height          =   180
  60.       Left            =   1848
  61.       TabIndex        =   1
  62.       Top             =   1008
  63.       Width           =   1020
  64.    End
  65.    Begin Label Path 
  66.       Height          =   180
  67.       Left            =   1848
  68.       TabIndex        =   8
  69.       Top             =   672
  70.       Width           =   1992
  71.    End
  72.    Begin Label Label1 
  73.       Caption         =   "&Files:"
  74.       Height          =   180
  75.       Left            =   168
  76.       TabIndex        =   0
  77.       Top             =   672
  78.       Width           =   600
  79.    End
  80.    Begin Label Label3 
  81.       Caption         =   "File &Name"
  82.       Height          =   180
  83.       Left            =   168
  84.       TabIndex        =   7
  85.       Top             =   168
  86.       Width           =   936
  87.    End
  88. 'Code for Visual Basic 1.0 and Windows 3.0
  89. '(C)1991 Marquis Computing. All Rights Reserved.
  90. 'File Dialog box manager. Uses Windows system calls to increase
  91. 'speed and give a dialog box that dosen't have "visual basic"
  92. 'stamped all over it!
  93. DefInt A-Z
  94. Declare Function DlgDirList Lib "User" (ByVal hDlg As Integer, ByVal lpPathSpec As String, ByVal nIDListBox As Integer, ByVal nIDStaticPath As Integer, ByVal wFiletype As Integer) As Integer
  95. Const TRUE = -1
  96. Const FALSE = 0
  97. '--- these constants are used by GetFileBox form
  98. Const File_Box = &H7
  99. Const Dir_Box = &H9
  100. Const DrivesAndDir = &H10 Or &H4000 Or &H8000
  101. Const FilesOnly = &H1
  102. Dim File_Mask As String
  103. Sub ChangeTo (FileSpec$)
  104.     On Error GoTo ErrorHandler
  105.     OldPath$ = CurDir$("")
  106.     If InStr(FileSpec$, "[-") Then      'drive
  107.         Drive$ = Mid$(FileSpec$, 3, Len(FileSpec$) - 3)
  108.         ChDrive Drive$
  109.         UpDateForm
  110.     ElseIf InStr(FileSpec$, "[") Then   'dir
  111.         SDir$ = Mid$(FileSpec$, 2, Len(FileSpec$) - 2)
  112.         ChDir SDir$
  113.         UpDateForm
  114.     Else
  115.     End If
  116.     Exit Sub
  117. ErrorHandler:
  118.     ChDrive OldPath$
  119.     ChDir OldPath$
  120.     Exit Sub
  121. End Sub
  122. Sub Command1_Click ()
  123.     GetFileBox.Hide
  124.     GetFileBox.Path = CurDir$
  125. End Sub
  126. Sub Command2_Click ()
  127.     GetFileBox.FileSpec.Text = ""
  128.     GetFileBox.Hide
  129. End Sub
  130. Sub Dirs_DblClick ()
  131.     '
  132.     '
  133.     '
  134.     FileSpec.Text = File_Mask
  135.     NewFileSpec$ = Dirs.Text
  136.     ChangeTo NewFileSpec$
  137. End Sub
  138. Sub Dirs_KeyDown (KeyCode As Integer, Shift As Integer)
  139.     FileSpec.Text = ProcessDir()
  140. End Sub
  141. Sub Dirs_KeyPress (KeyAscii As Integer)
  142.     If KeyAscii = 13 Then
  143.         FileSpec.Text = File_Mask
  144.         NewFileSpec$ = Dirs.Text
  145.         ChangeTo NewFileSpec$
  146.     End If
  147. End Sub
  148. Sub Dirs_KeyUp (KeyCode As Integer, Shift As Integer)
  149. FileSpec.Text = ProcessDir()
  150. End Sub
  151. Sub Dirs_MouseUp (Button As Integer, Shift As Integer, X As Single, Y As Single)
  152. FileSpec.Text = ProcessDir()
  153. End Sub
  154. Sub Files_DblClick ()
  155.     '
  156.     '
  157.     '
  158.     GetFileBox.Hide
  159. End Sub
  160. Sub Files_KeyDown (KeyCode As Integer, Shift As Integer)
  161.     FileSpec.Text = Files.Text
  162. End Sub
  163. Sub Files_KeyPress (KeyAscii As Integer)
  164.         If KeyAscii = 13 Then GetFileBox.Hide
  165. End Sub
  166. Sub Files_KeyUp (KeyCode As Integer, Shift As Integer)
  167.     FileSpec.Text = Files.Text
  168. End Sub
  169. Sub Files_MouseUp (Button As Integer, Shift As Integer, X As Single, Y As Single)
  170.     FileSpec.Text = Files.Text
  171. End Sub
  172. Sub FileSpec_KeyPress (KeyAscii As Integer)
  173.     If KeyAscii = 13 Then
  174.         FileSpec.Text = UCase$(FileSpec.Text)
  175.         KeyAscii = 0
  176.         UpDateForm
  177.     End If
  178. End Sub
  179. Sub Form_Load ()
  180.     '
  181.     'Center form
  182.     '
  183.     '--- Center form
  184.     Screen.MousePointer = 11
  185.     WinWidth = (Screen.Width - GetFileBox.Width) \ 2
  186.     WinHieght = (Screen.Height - GetFileBox.Height) \ 2
  187.     GetFileBox.Move WinWidth, WinHieght
  188.     '--- load the files box
  189.     If FileSpec.Text = "" Then FileSpec.Text = "*.*"
  190.     '--- display current path
  191.     ThisDir$ = LCase$(CurDir$)
  192.     If Len(ThisDir$) > 20 Then
  193.       ThisDir1$ = Left$(ThisDir$, 3)
  194.       ThisDir2$ = "..."
  195.       ThisDir3$ = Right$(ThisDir$, 15)
  196.       ThisDir$ = ThisDir1$ + ThisDir2$ + ThisDir3$
  197.     End If
  198.     GetFileBox.Path.Caption = ThisDir$
  199.     Screen.MousePointer = 0
  200. End Sub
  201. Sub Form_Resize ()
  202.     File_Mask = FileSpec.Text
  203.     '--- load the files box
  204.     LoadDir File_Box, File_Mask, FilesOnly
  205.     '--- load the dir/drive box
  206.     LoadDir Dir_Box, File_Mask, DrivesAndDir
  207. End Sub
  208. Function GetMask$ (FileSpec$)
  209.     '
  210.     '
  211.     '
  212.         
  213.     For X = Len(FileSpec$) To 1 Step -1
  214.       If Mid$(FileSpec$, X, 1) = "." Then
  215.         GetMask$ = "*" + Mid$(FileSpec$, X)
  216.         Exit For
  217.       End If
  218.     Next
  219. End Function
  220. Sub LoadDir (ListBox, Mask$, Item)
  221.     '
  222.     'Loads a listbox with a variety of disk file items. Usually the array
  223.     'of items are file(s), dir(s) or drive(s). Uses a windows system call
  224.     'for enhanced speed and versatility.
  225.     '
  226.     'On entry
  227.     '---------------------------------------------------------------------
  228.     'ListBox:   the number of the list box (i.e., 1,2 etc.)
  229.     '
  230.     'Mask$  :   a file specification mask (i.e., *.DBF, ?.DAT, *.SY?)
  231.     '
  232.     'Item   :   an integer which represents the type of item to load into
  233.     '           the list box where:
  234.     '
  235.     '           &H0     = read/write files only
  236.     '           &H1     = read-only files
  237.     '           &H2     = hidden files
  238.     '           &H4     = system files
  239.     '           &H10    = sub dirs
  240.     '           &H20    = archive
  241.     '           &H4000  = drives
  242.     '           &H8000  = force ONLY those items meeting Mask$ and Item%
  243.     '                     criteria to be loaded.
  244.     '
  245.     'NOTE:  Items may be OR'd to combine -- for example to load system files
  246.     '       and drives ONLY, you would set up Item% as follows:
  247.     '
  248.     '               Item% = &H4 Or &H4000 Or &H8000
  249.     'on exit
  250.     '--------------------------------------------
  251.     'The list box is filled with contents specified (if any found)
  252.     '
  253.     '
  254.      
  255.      '--- get windows handle of form
  256.      hDlg = GetFileBox.hWnd
  257.      
  258.      '--- ASCIIZ file spec
  259.      lpPathSpec$ = LTrim$(RTrim$(Mask$)) + Chr$(0)
  260.      '--- assign list box number
  261.      nIDListBox = ListBox
  262.      '--- no static path id
  263.      nIDStaticPath = 0
  264.      
  265.      '--- assign item
  266.      wFiletype = Item
  267.      
  268.      '--- call windows
  269.      dummy = DlgDirList(hDlg, lpPathSpec$, nIDListBox, nIDStaticPath, wFiletype)
  270. End Sub
  271. Function ProcessDir$ ()
  272.     '
  273.     '
  274.     '
  275.     Item$ = Dirs.Text
  276.     If InStr(Item$, "[-") Then          'drive
  277.         Item$ = Mid$(Item$, 3, 1) + ":"
  278.     ElseIf InStr(Item$, "[") Then      'directory
  279.         Item$ = Mid$(Item$, 2, Len(Item$) - 2)
  280.     End If
  281.     ProcessDir$ = Item$ + "\" + File_Mask
  282. End Function
  283. Sub UpDateForm ()
  284.     '
  285.     'Updates a form based on new filespec
  286.     '
  287.     NewFileSpec$ = GetFileBox.FileSpec.Text
  288.     LoadDir File_Box, NewFileSpec$, FilesOnly
  289.     LoadDir Dir_Box, NewFileSpec$, DrivesAndDir
  290.     GetFileBox.FileSpec.Text = GetMask(NewFileSpec$)
  291.     ThisDir$ = LCase$(CurDir$)
  292.     If Len(ThisDir$) > 20 Then
  293.       ThisDir1$ = Left$(ThisDir$, 3)
  294.       ThisDir2$ = "..."
  295.       ThisDir3$ = Right$(ThisDir$, 15)
  296.       ThisDir$ = ThisDir1$ + ThisDir2$ + ThisDir3$
  297.     End If
  298.     GetFileBox.Path.Caption = ThisDir$
  299. End Sub
  300.