frmMain.frm
Upload User: wintows
Upload Date: 2009-11-16
Package Size: 27k
Code Size: 12k
Category:

Windows Develop

Development Platform:

Visual Basic

  1. VERSION 5.00
  2. Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
  3. Begin VB.Form frmMain 
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "文件夹自动同步备份工具"
  6.    ClientHeight    =   3075
  7.    ClientLeft      =   150
  8.    ClientTop       =   435
  9.    ClientWidth     =   5925
  10.    Icon            =   "frmMain.frx":0000
  11.    LinkTopic       =   "Form1"
  12.    MaxButton       =   0   'False
  13.    MinButton       =   0   'False
  14.    ScaleHeight     =   3075
  15.    ScaleWidth      =   5925
  16.    StartUpPosition =   3  '窗口缺省
  17.    Begin VB.CommandButton cmdHide 
  18.       Caption         =   "h"
  19.       Height          =   255
  20.       Left            =   5445
  21.       TabIndex        =   18
  22.       ToolTipText     =   "隐藏界面"
  23.       Top             =   0
  24.       Width           =   255
  25.    End
  26.    Begin VB.CheckBox chkStartwithWindows 
  27.       Caption         =   "跟随Windows一起启动?"
  28.       Height          =   255
  29.       Left            =   120
  30.       TabIndex        =   17
  31.       Top             =   2040
  32.       Width           =   2655
  33.    End
  34.    Begin MSComctlLib.StatusBar status 
  35.       Align           =   2  'Align Bottom
  36.       Height          =   270
  37.       Left            =   0
  38.       TabIndex        =   16
  39.       Top             =   2805
  40.       Width           =   5925
  41.       _ExtentX        =   10451
  42.       _ExtentY        =   476
  43.       _Version        =   393216
  44.       BeginProperty Panels {8E3867A5-8586-11D1-B16A-00C0F0283628} 
  45.          NumPanels       =   3
  46.          BeginProperty Panel1 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
  47.             AutoSize        =   1
  48.             Object.Width           =   5265
  49.          EndProperty
  50.          BeginProperty Panel2 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
  51.             Style           =   5
  52.             TextSave        =   "14:54"
  53.          EndProperty
  54.          BeginProperty Panel3 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
  55.             Style           =   6
  56.             TextSave        =   "2007-09-18"
  57.          EndProperty
  58.       EndProperty
  59.    End
  60.    Begin VB.Frame frameFolders 
  61.       Caption         =   "文件夹选项"
  62.       Height          =   1335
  63.       Left            =   120
  64.       TabIndex        =   7
  65.       Top             =   555
  66.       Width           =   5535
  67.       Begin VB.TextBox txtDestination 
  68.          Height          =   375
  69.          Left            =   1200
  70.          TabIndex        =   12
  71.          Top             =   720
  72.          Width           =   3735
  73.       End
  74.       Begin VB.CommandButton Command2 
  75.          Caption         =   "..."
  76.          Height          =   375
  77.          Left            =   4965
  78.          TabIndex        =   11
  79.          Top             =   720
  80.          Width           =   450
  81.       End
  82.       Begin VB.TextBox txtSource 
  83.          Height          =   375
  84.          Left            =   1200
  85.          TabIndex        =   9
  86.          Top             =   240
  87.          Width           =   3735
  88.       End
  89.       Begin VB.CommandButton Command1 
  90.          Caption         =   "..."
  91.          Height          =   375
  92.          Left            =   4950
  93.          TabIndex        =   8
  94.          Top             =   240
  95.          Width           =   465
  96.       End
  97.       Begin VB.Label Label5 
  98.          Caption         =   "目标文件夹:"
  99.          Height          =   255
  100.          Left            =   180
  101.          TabIndex        =   13
  102.          Top             =   840
  103.          Width           =   2775
  104.       End
  105.       Begin VB.Label Label4 
  106.          Caption         =   "源文件夹:"
  107.          Height          =   255
  108.          Left            =   195
  109.          TabIndex        =   10
  110.          Top             =   360
  111.          Width           =   975
  112.       End
  113.    End
  114.    Begin VB.CheckBox chkFolderChange 
  115.       Caption         =   "当文件夹发生改变时."
  116.       Height          =   375
  117.       Left            =   3315
  118.       TabIndex        =   6
  119.       Top             =   120
  120.       Width           =   2145
  121.    End
  122.    Begin VB.TextBox txtFileType 
  123.       Height          =   375
  124.       Left            =   840
  125.       TabIndex        =   4
  126.       Top             =   1080
  127.       Visible         =   0   'False
  128.       Width           =   1815
  129.    End
  130.    Begin VB.TextBox txtMins 
  131.       Alignment       =   1  'Right Justify
  132.       BeginProperty Font 
  133.          Name            =   "Verdana"
  134.          Size            =   8.25
  135.          Charset         =   0
  136.          Weight          =   400
  137.          Underline       =   0   'False
  138.          Italic          =   0   'False
  139.          Strikethrough   =   0   'False
  140.       EndProperty
  141.       Height          =   285
  142.       Left            =   1440
  143.       TabIndex        =   1
  144.       Text            =   "1"
  145.       Top             =   120
  146.       Width           =   375
  147.    End
  148.    Begin VB.Timer Timer1 
  149.       Interval        =   60000
  150.       Left            =   15
  151.       Top             =   1260
  152.    End
  153.    Begin VB.CommandButton cmdStart 
  154.       Caption         =   "开始"
  155.       Height          =   375
  156.       Left            =   3840
  157.       TabIndex        =   0
  158.       Top             =   1935
  159.       Width           =   1815
  160.    End
  161.    Begin VB.Label Label6 
  162.       Alignment       =   2  'Center
  163.       Caption         =   "/ 或者 /"
  164.       Height          =   270
  165.       Left            =   2325
  166.       TabIndex        =   14
  167.       Top             =   195
  168.       Width           =   1035
  169.    End
  170.    Begin VB.Label Label7 
  171.       Caption         =   "分钟"
  172.       Height          =   240
  173.       Left            =   1920
  174.       TabIndex        =   15
  175.       Top             =   195
  176.       Width           =   1335
  177.    End
  178.    Begin VB.Label Label3 
  179.       Caption         =   "File Type"
  180.       Height          =   255
  181.       Left            =   0
  182.       TabIndex        =   5
  183.       Top             =   1200
  184.       Visible         =   0   'False
  185.       Width           =   735
  186.    End
  187.    Begin VB.Label Label2 
  188.       Caption         =   "mins"
  189.       Height          =   375
  190.       Left            =   1680
  191.       TabIndex        =   3
  192.       Top             =   720
  193.       Width           =   615
  194.    End
  195.    Begin VB.Label Label1 
  196.       Caption         =   "备份周期:"
  197.       Height          =   255
  198.       Left            =   240
  199.       TabIndex        =   2
  200.       Top             =   180
  201.       Width           =   1335
  202.    End
  203.    Begin VB.Menu menuSystray 
  204.       Caption         =   "doesnt matter"
  205.       Visible         =   0   'False
  206.       Begin VB.Menu menuStart 
  207.          Caption         =   "开始监视"
  208.       End
  209.       Begin VB.Menu menuStop 
  210.          Caption         =   "停止监视"
  211.       End
  212.       Begin VB.Menu menuLine1 
  213.          Caption         =   "-"
  214.       End
  215.       Begin VB.Menu menuShow 
  216.          Caption         =   "显示界面"
  217.       End
  218.       Begin VB.Menu menuHide 
  219.          Caption         =   "隐藏界面"
  220.       End
  221.       Begin VB.Menu menuLine2 
  222.          Caption         =   "-"
  223.       End
  224.       Begin VB.Menu menuExit 
  225.          Caption         =   "退出"
  226.       End
  227.    End
  228. End
  229. Attribute VB_Name = "frmMain"
  230. Attribute VB_GlobalNameSpace = False
  231. Attribute VB_Creatable = False
  232. Attribute VB_PredeclaredId = True
  233. Attribute VB_Exposed = False
  234. 'Download by http://www.codefans.net
  235. Private Sub chkFolderChange_Click()
  236.     Call RegSave(chkFolderChange, chkFolderChange.Value)
  237.     txtMins.Enabled = Not CBool(chkFolderChange.Value)
  238. End Sub
  239. Private Sub chkStartwithWindows_Click()
  240.     SaveSetting App.EXEName, "start", "autoBoot", chkStartwithWindows
  241.     Select Case chkStartwithWindows
  242.         Case 0
  243.         DoNotStartUp App.Path & "" & App.EXEName & ".exe", App.EXEName
  244.         Case 1
  245.         DoStartUp App.Path & "" & App.EXEName & ".exe", App.EXEName
  246.     End Select
  247. End Sub
  248. Private Sub cmdHide_Click()
  249.  Me.Visible = False
  250.  SaveSetting App.EXEName, "start", "hide", 1
  251. End Sub
  252. Private Sub cmdStart_Click()
  253.     On Error Resume Next
  254.     If txtMins = "" Then
  255.         msg = MsgBox("你必须输入备份周期才能备份. 默认为1分钟.", vbInformation, "提示")
  256.         Exit Sub
  257.     End If
  258.     If txtDestination <> "" And txtSource <> "" Then
  259.         status.Panels(1).Text = "Backing up..."
  260.         'Copy files to destination
  261.         'Call CopyFolder(txtSource, txtDestination, fasle, True)
  262.         Call SynchronizeDirectoryTrees(txtSource, txtDestination, False)
  263.         status.Panels(1).Text = "完毕."
  264.         If cmdStart.Caption = "开始" Then
  265.             If chkFolderChange.Value = 1 Then
  266.                 Call WatchDIR_Start(txtSource)
  267.                 Exit Sub
  268.             End If
  269.             If txtMins <> "" Then
  270.                 ourval = (60 * CInt(txtMins.Text))
  271.                 ourval = ourval * 1000
  272.                 Timer1.interval = ourval
  273.                 Timer1.Enabled = True
  274.             End If
  275.             cmdStart.Caption = "停止"
  276.         Else
  277.             Call WatchDIR_End
  278.             Timer1.Enabled = False
  279.             cmdStart.Caption = "开始"
  280.         End If
  281.     Else
  282.         msg = MsgBox("你必须输入源文件夹和目标文件夹!", vbInformation, "提示")
  283.     End If
  284. End Sub
  285. Private Sub Command1_Click()
  286.     txtSource = GetDirectory(Me)
  287.     Call RegSave(txtSource, txtSource.Text)
  288. End Sub
  289. Private Sub Command2_Click()
  290.     txtDestination = GetDirectory(Me)
  291.     Call RegSave(txtDestination, txtDestination.Text)
  292. End Sub
  293. Private Sub Form_Load()
  294.     With nid 'with system tray
  295.         .cbSize = Len(nid)
  296.         .hwnd = Me.hwnd
  297.         .uId = vbNull
  298.         .uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
  299.         .uCallBackMessage = WM_MOUSEMOVE
  300.         .hIcon = Me.Icon 'use form's icon in tray
  301.         .szTip = "文件检视中..."
  302.     End With
  303.     Shell_NotifyIcon NIM_ADD, nid 'add to tray
  304.     txtSource = RegLoad(txtSource)
  305.     ChkVal = RegLoad(chkFolderChange)
  306.     If ChkVal <> "" Then
  307.         chkFolderChange.Value = ChkVal
  308.     End If
  309.     txtDestination = RegLoad(txtDestination)
  310.     Me.Visible = Not CBool(GetSetting(App.EXEName, "start", "hide", 0))
  311.     chkStartwithWindows = GetSetting(App.EXEName, "start", "autoboot", 0)
  312. End Sub
  313. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  314.     Dim Result, Action As Long
  315.     If Me.ScaleMode = vbPixels Then
  316.         Action = X
  317.     Else
  318.         Action = X / Screen.TwipsPerPixelX
  319.     End If
  320.     Select Case Action
  321.         Case WM_LBUTTONDBLCLK 'Left Button Double Click
  322.         Me.WindowState = vbNormal 'put into taskbar
  323.         Result = SetForegroundWindow(Me.hwnd)
  324.         Me.Show 'show form
  325.         Case WM_RBUTTONUP 'Right Button Up
  326.         Result = SetForegroundWindow(Me.hwnd)
  327.         PopupMenu menuSystray 'popup menu, cool eh?
  328.     End Select
  329. End Sub
  330. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  331.     Call WatchDIR_End
  332. End Sub
  333. Private Sub Form_Unload(Cancel As Integer)
  334.     Shell_NotifyIcon NIM_DELETE, nid
  335.     Call WatchDIR_End
  336. End Sub
  337. Private Sub mnuEvery_Click()
  338.     chkFolderChange.Enabled = True
  339.     txtMins.Enabled = False
  340. End Sub
  341. Private Sub menuExit_Click()
  342.     Unload Me
  343.     End
  344. End Sub
  345. Private Sub menuHide_Click()
  346.     Me.Visible = False
  347. End Sub
  348. Private Sub menuShow_Click()
  349.     Me.Visible = True
  350. End Sub
  351. Private Sub menuStart_Click()
  352.     If chkFolderChange.Value = 1 Then
  353.         Call WatchDIR_Start(txtSource)
  354.         Exit Sub
  355.     End If
  356.     If txtMins <> "" Then
  357.         ourval = (60 * CInt(txtMins.Text))
  358.         ourval = ourval * 1000
  359.         Timer1.interval = ourval
  360.         Timer1.Enabled = True
  361.     End If
  362.     cmdStart.Caption = "停止"
  363. End Sub
  364. Private Sub menuStop_Click()
  365.     Call WatchDIR_End
  366.     Timer1.Enabled = False
  367.     cmdStart.Caption = "开始"
  368. End Sub
  369. Private Sub Timer1_Timer()
  370.     status.Panels(1).Text = "正在备份中..."
  371.     'Copy files to destination
  372.     'Call CopyFolder(txtSource, txtDestination, fasle, True)
  373.     Call SynchronizeDirectoryTrees(txtSource, txtDestination, False)
  374.     status.Panels(1).Text = "备份完毕."
  375. End Sub
  376. Private Sub txtMins_Change()
  377.     Call RegSave(txtMins, txtMins.Name)
  378. End Sub