⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmencrypt.frm

📁 该软件是为文本文件的数据安全性而编制的
💻 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  '文本文件的内容信息
    
   
   '按浏览按钮选择文本文件名
    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    '备件文件存在
          '空语句 ('备件文件已存在,则不在创建备件文件)
       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  '读取文本文件内容到FileContext中
        Loop
        f.Close
        Set f = fs.OpenTextFile(TxtFileName.Text, ForWriting, TristateFalse)
        f.Write MydsEncrypt.Encode(FileContext, 1) '加密后的内容写回原文本文件中
        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  '读取文本文件内容到FileContext中
         Loop
         f.Close
         Set f = fs.OpenTextFile(TxtFileName.Text, ForWriting, TristateFalse)
         f.Write MydsEncrypt.Decode(FileContext, 1)  '解密后的内容写回原文本文件中
         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
      
   '实现无标题窗体拖动
  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 + -