home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / CODE_UPLOAD170663142001.psc / frmMain.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  2001-03-15  |  13.0 KB  |  373 lines

  1. VERSION 5.00
  2. Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
  3. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
  4. Begin VB.Form frmMain 
  5.    Caption         =   "My Multi Downloader"
  6.    ClientHeight    =   4500
  7.    ClientLeft      =   165
  8.    ClientTop       =   735
  9.    ClientWidth     =   8535
  10.    LinkTopic       =   "Form1"
  11.    OLEDropMode     =   1  '
  12.    ScaleHeight     =   4500
  13.    ScaleWidth      =   8535
  14.    StartUpPosition =   3  'Windows 
  15.    Begin VB.TextBox txtMaxActive 
  16.       Height          =   270
  17.       Left            =   1320
  18.       TabIndex        =   17
  19.       Text            =   "20"
  20.       Top             =   3000
  21.       Width           =   375
  22.    End
  23.    Begin MSComDlg.CommonDialog CommonDialog1 
  24.       Left            =   3840
  25.       Top             =   3720
  26.       _ExtentX        =   847
  27.       _ExtentY        =   847
  28.       _Version        =   393216
  29.    End
  30.    Begin VB.Timer Timer1 
  31.       Left            =   3240
  32.       Top             =   3720
  33.    End
  34.    Begin VB.CommandButton cmdClear 
  35.       Caption         =   "Clear"
  36.       Height          =   375
  37.       Left            =   7680
  38.       TabIndex        =   15
  39.       Top             =   240
  40.       Width           =   735
  41.    End
  42.    Begin VB.CommandButton cmdRemove 
  43.       Caption         =   "Remove"
  44.       Height          =   375
  45.       Left            =   6600
  46.       TabIndex        =   14
  47.       Top             =   240
  48.       Width           =   975
  49.    End
  50.    Begin VB.CheckBox chkOnTop 
  51.       Caption         =   "Always on top "
  52.       Height          =   255
  53.       Left            =   6840
  54.       TabIndex        =   13
  55.       Top             =   3000
  56.       Value           =   1  '
  57.       Width           =   1575
  58.    End
  59.    Begin VB.CommandButton cmdChangePath 
  60.       Caption         =   "Change"
  61.       Height          =   375
  62.       Left            =   120
  63.       TabIndex        =   12
  64.       Top             =   3720
  65.       Width           =   855
  66.    End
  67.    Begin VB.TextBox txtSavePath 
  68.       Height          =   270
  69.       Left            =   1320
  70.       TabIndex        =   11
  71.       Top             =   3360
  72.       Width           =   7095
  73.    End
  74.    Begin VB.TextBox txtExtension 
  75.       Height          =   270
  76.       Left            =   5640
  77.       TabIndex        =   9
  78.       Text            =   "au"
  79.       Top             =   3000
  80.       Width           =   615
  81.    End
  82.    Begin VB.CheckBox chkRenameExtension 
  83.       Caption         =   "Rename extension:"
  84.       Height          =   375
  85.       Left            =   4320
  86.       TabIndex        =   8
  87.       Top             =   2925
  88.       Width           =   1215
  89.    End
  90.    Begin VB.ListBox listSave 
  91.       Height          =   240
  92.       Left            =   3120
  93.       OLEDropMode     =   1  '
  94.       TabIndex        =   7
  95.       Top             =   3000
  96.       Visible         =   0   'False
  97.       Width           =   495
  98.    End
  99.    Begin VB.CommandButton cmdAdd 
  100.       Caption         =   "Add"
  101.       Height          =   375
  102.       Left            =   5760
  103.       TabIndex        =   6
  104.       Top             =   240
  105.       Width           =   735
  106.    End
  107.    Begin VB.ComboBox cboURL 
  108.       Height          =   300
  109.       Left            =   120
  110.       OLEDropMode     =   1  '
  111.       TabIndex        =   5
  112.       Top             =   240
  113.       Width           =   5535
  114.    End
  115.    Begin VB.ListBox listURL 
  116.       Height          =   2040
  117.       Left            =   120
  118.       OLEDropMode     =   1  '
  119.       TabIndex        =   4
  120.       Top             =   720
  121.       Width           =   8295
  122.    End
  123.    Begin VB.CommandButton cmdStop 
  124.       Caption         =   "Stop"
  125.       Height          =   375
  126.       Left            =   7560
  127.       TabIndex        =   3
  128.       Top             =   3720
  129.       Width           =   855
  130.    End
  131.    Begin VB.CommandButton cmdStart 
  132.       Caption         =   "Start"
  133.       Height          =   375
  134.       Left            =   6600
  135.       TabIndex        =   2
  136.       Top             =   3720
  137.       Width           =   855
  138.    End
  139.    Begin MSComctlLib.ProgressBar ProgressBar1 
  140.       Height          =   255
  141.       Left            =   240
  142.       TabIndex        =   1
  143.       Top             =   7200
  144.       Width           =   3495
  145.       _ExtentX        =   6165
  146.       _ExtentY        =   450
  147.       _Version        =   393216
  148.       Appearance      =   1
  149.    End
  150.    Begin MSComctlLib.StatusBar StatusBar 
  151.       Align           =   2  '
  152.       Height          =   330
  153.       Left            =   0
  154.       TabIndex        =   0
  155.       Top             =   4170
  156.       Width           =   8535
  157.       _ExtentX        =   15055
  158.       _ExtentY        =   582
  159.       _Version        =   393216
  160.       BeginProperty Panels {8E3867A5-8586-11D1-B16A-00C0F0283628} 
  161.          NumPanels       =   2
  162.          BeginProperty Panel1 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
  163.             Object.Width           =   5292
  164.             MinWidth        =   5292
  165.          EndProperty
  166.          BeginProperty Panel2 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
  167.             Object.Width           =   8819
  168.             MinWidth        =   8819
  169.          EndProperty
  170.       EndProperty
  171.    End
  172.    Begin VB.Label lblMaxActive 
  173.       Caption         =   "Max active:"
  174.       Height          =   255
  175.       Left            =   120
  176.       TabIndex        =   16
  177.       Top             =   3000
  178.       Width           =   1095
  179.    End
  180.    Begin VB.Label lblSavePath 
  181.       Caption         =   "Save path:"
  182.       Height          =   255
  183.       Left            =   120
  184.       TabIndex        =   10
  185.       Top             =   3375
  186.       Width           =   1095
  187.    End
  188.    Begin VB.Menu mnuPopup 
  189.       Caption         =   "Popup"
  190.       Begin VB.Menu mnuPopupFileOpen 
  191.          Caption         =   "Open File"
  192.       End
  193.       Begin VB.Menu mnuPopupFileSave 
  194.          Caption         =   "Save As"
  195.       End
  196.       Begin VB.Menu bar1 
  197.          Caption         =   "-"
  198.       End
  199.       Begin VB.Menu mnuPopupOpenURL 
  200.          Caption         =   "Open URL"
  201.       End
  202.       Begin VB.Menu mnuPopupOpenDownload 
  203.          Caption         =   "Open Downlaoded File"
  204.       End
  205.    End
  206. Attribute VB_Name = "frmMain"
  207. Attribute VB_GlobalNameSpace = False
  208. Attribute VB_Creatable = False
  209. Attribute VB_PredeclaredId = True
  210. Attribute VB_Exposed = False
  211. '----------------------------------------------------------------------------------------'
  212. ' Multi Downloader using multithreadings
  213. ' Created by Suk Yong Kim, 03/14/2001
  214. ' This project is my first project to upload to the PSC.
  215. ' Many persons contribute to create this project
  216. ' I really appreicate their efforts and codes and the great server PSC.
  217. ' if any question, mail to : techtrans@dreamwiz.com
  218. '----------------------------------------------------------------------------------------'
  219. 'API Declarations
  220. Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
  221. Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
  222. 'API  and constant for listbox tool tip
  223. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
  224.     (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
  225. Private Const LB_ITEMFROMPOINT = &H1A9
  226. Private Const EM_GETLINECOUNT = &HBA
  227. 'Flag to diable the list box click event when open a file
  228. Public bDisableClickEvent As Boolean
  229. 'Class Module Collection for control of multi threads
  230. Private cThreadControls As New clsThreadings
  231. 'Winddow minimum size value
  232. Private sglFixedWidth As Single
  233. Private sglFixedHeight As Single
  234. 'put the form on top or take down
  235. Private Sub chkOnTop_Click()
  236.     If chkOnTop.Value = vbChecked Then
  237.         Call putMeOnTop(Me)
  238.     Else
  239.         Call takeMeDown(Me)
  240.     End If
  241. End Sub
  242. 'Rename the extension when save to the local folder
  243. Private Sub chkRenameExtension_Click()
  244.     txtExtension.Enabled = IIf(chkRenameExtension.Value = vbChecked, True, False)
  245. End Sub
  246. 'Add the text in the combo box  to the list box
  247. Private Sub cmdAdd_Click()
  248.     Call AddURL(cboURL.Text)
  249. End Sub
  250. 'To show the current total of list box items
  251. Sub ShowSatus()
  252.     StatusBar.Panels(1).Text = "Total: " & listURL.ListCount
  253.     If listURL.ListIndex < 0 Then
  254.         StatusBar.Panels(2).Text = ""
  255.     Else
  256.         StatusBar.Panels(2).Text = fnGetShortName(listSave.List(listURL.ListIndex))
  257.     End If
  258. End Sub
  259. 'Add the URL obtained through drag and drop or combo box to lis box
  260. Function AddURL(ByVal Item As String)
  261.     Dim ItemSave As String
  262.     Item = Trim(Replace(Item, vbCrLf, Space(1))) 'convert vbcrlf to space
  263.     If Len(Item) = 0 Then Exit Function
  264.     If Not IsInList(listURL, Item) Then ' if not in list box, add it
  265.         Dim IsWebURL As Boolean
  266.         If fnIsURL(Item, , , IsWebURL) And IsWebURL Then 'check it is web url, not local url
  267.             cboURL.AddItem Item
  268.             listURL.AddItem Item
  269.         End If
  270.     End If
  271.     Call ShowSatus
  272.     Call ChangeSaveFileName
  273. End Function
  274. Function ChangeSaveFileName()
  275.     'when filenames are same, change it
  276.     'this function is also used to show the list box tool tips and statusbar text
  277.     'which shows thelocal save files names of the selected lisbox item
  278.     'to do this, it use the a hidden list box, listSave
  279.     Dim ItemSaveName As String
  280.     Dim ItemSavePathName As String
  281.     Dim ItemSavePath As String
  282.     listSave.Clear 'Clear the listSave
  283.     ItemSavePath = fnGetPathRemoveEndDelimeter(txtSavePath)
  284.     Dim i As Long
  285.     For i = 0 To listURL.ListCount - 1 'Get local save filenames
  286.         
  287.         ItemSaveName = fnGetFileName(listURL.List(i), True)
  288.         ItemSavePathName = ItemSavePath & "\" & ItemSaveName
  289.         
  290.         If IsInList(listSave, ItemSavePathName) Then
  291.             Dim strTempName As String
  292.             Dim strTempExt As String, strTemp As String
  293.             Dim iNum As Integer
  294.             strTempName = fnGetNetFileName(ItemSaveName)
  295.             strTempExt = fnGetExtension(ItemSaveName)
  296.             strTemp = strTempName & "." & strTempExt
  297.             
  298.             iNum = 1
  299.             Do
  300.                strTemp = ItemSavePath & "\" & strTempName & "(" & iNum & ")" & "." & strTempExt
  301.                iNum = iNum + 1
  302.             Loop Until Not IsInList(listSave, strTemp)
  303.             
  304.             ItemSavePathName = strTemp
  305.         End If
  306.         'rename the extension if check box is checked
  307.         If chkRenameExtension.Value = vbChecked And Len(txtExtension) > 0 Then
  308.                 ItemSavePathName = ItemSavePathName & "." & txtExtension
  309.         End If
  310.         
  311.         listSave.AddItem ItemSavePathName 'Add the local save filenames
  312.     Next
  313. End Function
  314. Function IsInList(list_box As ListBox, Item As String) 'used to check an item is already in the list box
  315.     Dim i  As Long
  316.     For i = 0 To list_box.ListCount - 1
  317.         If list_box.List(i) = Item Then IsInList = True: Exit For
  318.     Next
  319. End Function
  320. Private Sub cmdChangePath_Click()
  321.     Dim Folder As String
  322.     Call takeMeDown(Me) 'take down the form that the browser for foder window is on the top
  323.     Folder = BrowseForFolder(txtSavePath, "Select the folder to save downloads.")
  324.     If Len(Folder) Then ' if not the cancel button is clicked
  325.         txtSavePath = Folder
  326.         Call ChangeSaveFileName 'change the listSave items to reflect the change of save  path
  327.         If listURL.ListIndex < 0 Then
  328.             StatusBar.Panels(2).Text = ""
  329.         Else
  330.             StatusBar.Panels(2).Text = fnGetShortName(listSave.List(listURL.ListIndex))
  331.         End If
  332.     End If
  333.      'put the form on top if chck box is chekced
  334.     If Me.chkOnTop.Value = vbChecked Then Call putMeOnTop(Me)
  335. End Sub
  336. Private Sub cmdClear_Click()
  337.     listURL.Clear
  338.     Call ShowSatus
  339. End Sub
  340. Private Sub cmdRemove_Click()
  341.     Dim i As Long
  342.     For i = listURL.ListCount - 1 To 0 Step -1
  343.         If listURL.Selected(i) Then
  344.             listURL.RemoveItem i
  345.             Exit For
  346.         End If
  347.     Next
  348.     If i = 0 And listURL.ListCount > 0 Then
  349.         listURL.ListIndex = 0 'select first item
  350.     ElseIf i <= listURL.ListCount - 1 Then
  351.         listURL.ListIndex = i 'select next item
  352.     ElseIf listURL.ListCount > 0 Then 'select last item
  353.         listURL.ListIndex = listURL.ListCount - 1
  354.     End If
  355.     Call ChangeSaveFileName 'refelct the change of list items
  356.     Call ShowSatus
  357. End Sub
  358. Private Sub cmdStart_Click()
  359.     On Error Resume Next
  360.     If listURL.ListCount < 1 Then Exit Sub 'if there is no item to download, exit sub
  361.      'if the save path does not exists
  362.      'ask whether to create i  CaBItem to download, e5        u'ask f the sav,ecke        If list_box.List(i) = Item Then IsInList = True: Exit For
  363.     Next
  364. End Function
  365. EnEnE Then  ThenOemp
  366.      ndexenOemp    S     listURL.ListIndex = i 'select st_Click()
  367.     On Error      =  OX Exit For
  368.     Next
  369.  the sav,eiwnlseiwnlseiwkI8ie6        ItemSavlick()
  370.    br to create i  CaBItems3
  371. ossssl42od'e i  CTsTempName & "." & strTempExt
  372.             
  373.