?? frmencrypt.frm
字號:
VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "comdlg32.ocx"
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "mscomctl.ocx"
Begin VB.Form frmEncrypt
AutoRedraw = -1 'True
BorderStyle = 0 'None
Caption = "文本文件加密器"
ClientHeight = 1620
ClientLeft = 0
ClientTop = 30
ClientWidth = 5325
Icon = "frmEncrypt.frx":0000
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 1620
ScaleWidth = 5325
ShowInTaskbar = 0 'False
StartUpPosition = 2 '屏幕中心
Begin MSComctlLib.ProgressBar ProgressBar1
Height = 195
Left = 1560
TabIndex = 7
Top = 360
Visible = 0 'False
Width = 2680
_ExtentX = 4736
_ExtentY = 344
_Version = 393216
Appearance = 1
Min = 1
End
Begin VB.CommandButton Command1
Height = 375
Index = 3
Left = 3322
Picture = "frmEncrypt.frx":030A
Style = 1 'Graphical
TabIndex = 4
ToolTipText = "退出程序"
Top = 1035
Width = 810
End
Begin MSComDlg.CommonDialog CommonDialog1
Left = 4320
Top = 1080
_ExtentX = 847
_ExtentY = 847
_Version = 393216
End
Begin VB.CommandButton Command1
Height = 375
Index = 2
Left = 2257
Picture = "frmEncrypt.frx":06E1
Style = 1 'Graphical
TabIndex = 3
ToolTipText = "解密文件"
Top = 1035
Width = 810
End
Begin VB.CommandButton Command1
Height = 375
Index = 1
Left = 4350
Picture = "frmEncrypt.frx":0AC9
Style = 1 'Graphical
TabIndex = 1
ToolTipText = "游覽文件"
Top = 548
Width = 810
End
Begin VB.TextBox TxtFileName
Height = 270
Left = 120
TabIndex = 0
Top = 600
Width = 4215
End
Begin VB.CommandButton Command1
Height = 375
Index = 0
Left = 1192
Picture = "frmEncrypt.frx":0EA8
Style = 1 'Graphical
TabIndex = 2
ToolTipText = "加密文件"
Top = 1035
Width = 810
End
Begin VB.PictureBox ImageList1
BackColor = &H80000005&
Height = 480
Left = 5445
ScaleHeight = 420
ScaleWidth = 1140
TabIndex = 5
Top = 5760
Width = 1200
End
Begin VB.Label Label1
BackStyle = 0 'Transparent
Caption = "文本文件名:"
ForeColor = &H00400000&
Height = 210
Left = 480
TabIndex = 6
Top = 360
Width = 1095
End
Begin VB.Image Image1
Height = 1825
Left = -180
Picture = "frmEncrypt.frx":128A
Stretch = -1 'True
Top = -105
Width = 5700
End
End
Attribute VB_Name = "frmEncrypt"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'
'說明:
' 文本文件加密算法及窗體制作方法
'日期:1999.05.13
'編者:徐景周
'
Option Explicit
Private MydsEncrypt As dsEncrypt
Dim fs As Variant '文件名柄
Dim f As Variant
Private Sub Command1_Click(Index As Integer)
Dim FileContext As String '文本文件的內(nèi)容信息
'按瀏覽按鈕選擇文本文件名
If Index = 1 Then
CommonDialog1.DialogTitle = "請選擇文本文件名"
CommonDialog1.Filter = "文本文件(*.Txt,*.Wri,*.Doc,*.Wps)|*.txt;*.wri;*.doc;*.wps|所有文件(*.*)|*.*"
CommonDialog1.ShowOpen
If CommonDialog1.FileName <> "" Then
TxtFileName.Text = CommonDialog1.FileName '在文本框中顯示選中的文件名
Command1(0).Enabled = True '加、解密按鈕置為有效
Command1(2).Enabled = True
End If
End If
'按加密按鈕時對文件的加密處理
If Index = 0 Then
If TxtFileName.Text <> "" Then '文件名不為空
If fs.FileExists(TxtFileName.Text) Then '文件名存在
If fs.FileExists(Left(TxtFileName.Text, Len(TxtFileName.Text) - 4) & ".bak") Then '備件文件存在
'空語句 ('備件文件已存在,則不在創(chuàng)建備件文件)
Else
fs.CopyFile TxtFileName.Text, Left(TxtFileName.Text, Len(TxtFileName.Text) - 4) & ".bak" '建立原文本文件備件
End If
Set f = fs.OpenTextFile(TxtFileName.Text, ForReading, TristateFalse)
Do While f.AtEndOfStream <> True
FileContext = FileContext & f.ReadLine & vbCrLf '讀取文本文件內(nèi)容到FileContext中
Loop
f.Close
Set f = fs.OpenTextFile(TxtFileName.Text, ForWriting, TristateFalse)
f.Write MydsEncrypt.Encode(FileContext, 1) '加密后的內(nèi)容寫回原文本文件中
f.Close
Command1(0).Enabled = False '加密按鈕置為無效
Else
MsgBox TxtFileName.Text & "文件不存在!", vbInformation, "提示"
TxtFileName.Text = ""
End If
Else
MsgBox "文本文件名不能為空!", vbInformation, "提示"
End If
End If
'按解密按鈕時對文件的解密處理
If Index = 2 Then
If TxtFileName.Text <> "" Then
If fs.FileExists(TxtFileName.Text) Then '文件名存在
Set f = fs.OpenTextFile(TxtFileName.Text, ForReading, TristateFalse)
Do While f.AtEndOfStream <> True
FileContext = FileContext & f.ReadLine '讀取文本文件內(nèi)容到FileContext中
Loop
f.Close
Set f = fs.OpenTextFile(TxtFileName.Text, ForWriting, TristateFalse)
f.Write MydsEncrypt.Decode(FileContext, 1) '解密后的內(nèi)容寫回原文本文件中
f.Close
Command1(2).Enabled = False '解密按鈕置為無效
Else
MsgBox TxtFileName.Text & "文件不存在!", vbInformation, "提示"
TxtFileName.Text = ""
End If
Else
MsgBox "文本文件名不能為空!", vbInformation, "提示"
End If
End If
'按退出按鈕則退出程序
If Index = 3 Then
Unload Me
End If
End Sub
Private Sub Form_Load()
If App.PrevInstance = True Then End '若已存在一個進程實例則退出
Set MydsEncrypt = New dsEncrypt
' MydsEncrypt.KeyString = ("XJZghlyj")
Set fs = CreateObject("Scripting.FileSystemObject") '建立文件對象
' 制作圓角窗體形狀
SetWindowRgn hWnd, CreateEllipticRgn(0, 0, frmEncrypt.Width / Screen.TwipsPerPixelX, frmEncrypt.Height / Screen.TwipsPerPixelY), True
' 制作橢圓按鈕
SetWindowRgn Command1(0).hWnd, CreateEllipticRgn(0, 0, Command1(0).Width / Screen.TwipsPerPixelX, Command1(0).Height / Screen.TwipsPerPixelY), True
SetWindowRgn Command1(1).hWnd, CreateEllipticRgn(0, 0, Command1(1).Width / Screen.TwipsPerPixelX, Command1(1).Height / Screen.TwipsPerPixelY), True
SetWindowRgn Command1(2).hWnd, CreateEllipticRgn(0, 0, Command1(2).Width / Screen.TwipsPerPixelX, Command1(2).Height / Screen.TwipsPerPixelY), True
SetWindowRgn Command1(3).hWnd, CreateEllipticRgn(0, 0, Command1(3).Width / Screen.TwipsPerPixelX, Command1(3).Height / Screen.TwipsPerPixelY), True
'實現(xiàn)無標題窗體拖動
PROROC = SetWindowLong(hWnd, GWL_WNDPROC, AddressOf WindowProc)
'加、解密按鈕無效圖形和有效圖形相同
Command1(0).DisabledPicture = Command1(0).Picture
Command1(2).DisabledPicture = Command1(2).Picture
End Sub
Private Sub Form_Unload(Cancel As Integer)
Dim rv As Long
rv = SetWindowLong(hWnd, GWL_WNDPROC, PROROC) '恢復標題欄拖動
End Sub
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -