End SubPrivate Sub TxtFile_Change() ' End SubPrivate Sub TxtFile_KeyPress(KeyAscii As Integer) If KeyAscii = vbKeyReturn Then LoadHex TxtFile.Text End If
End SubPrivate Sub LoadHex(FileStr As String) Dim LoadBytes() As Byte Dim FileNum As Integer Dim FileSize As Long Dim ArrayMax As Long Dim AllStr As String Dim TempStr As String Dim TempPtr As Long Dim I As Long
FileNum = FreeFile
On Error GoTo ErrLoad Open TxtFile.Text For Binary Access Read Lock Write As #FileNum On Error GoTo 0
Me.MousePointer = 13 DoEvents
FileSize = LOF(FileNum)
If FileSize <= 0 Then RText1.Text = "": Exit Sub ArrayMax = FileSize - 1
ReDim LoadBytes(0 To ArrayMax) Get #FileNum, , LoadBytes
Close #FileNum
AllStr = Space(FileSize * 6)
TempPtr = StrPtr(AllStr) For I = 0 To ArrayMax TempStr = Hex$(LoadBytes(I) \ &H10) + Hex$(LoadBytes(I) And &HF) Call CopyMemory(ByVal TempPtr + I * 6, ByVal StrPtr(TempStr), 6) Next I
End SubPrivate Sub TxtFile_Change() ' End SubPrivate Sub TxtFile_KeyPress(KeyAscii As Integer) If KeyAscii = vbKeyReturn Then LoadHex TxtFile.Text End If
End SubPrivate Sub LoadHex(FileStr As String) Dim LoadBytes() As Byte Dim FileNum As Integer Dim FileSize As Long Dim ArrayMax As Long Dim AllStr As String Dim TempStr As String Dim TempPtr As Long Dim I As Long
FileNum = FreeFile
On Error GoTo ErrLoad Open TxtFile.Text For Binary Access Read Lock Write As #FileNum On Error GoTo 0
Me.MousePointer = 13 DoEvents
FileSize = LOF(FileNum)
If FileSize <= 0 Then RText1.Text = "": Exit Sub ArrayMax = FileSize - 1
ReDim LoadBytes(0 To ArrayMax) Get #FileNum, , LoadBytes
Close #FileNum
AllStr = Space(FileSize * 6)
TempPtr = StrPtr(AllStr) For I = 0 To ArrayMax TempStr = Hex$(LoadBytes(I) \ &H10) + Hex$(LoadBytes(I) And &HF) Call CopyMemory(ByVal TempPtr + I * 6, ByVal StrPtr(TempStr), 6) Next I
复制下列内容到记事本。保存为“FrmHexView.frm”。
====================================================================
VERSION 5.00
Object = "{3B7C8863-D78F-101B-B9B5-04021C009402}#1.2#0"; "RICHTX32.OCX"
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Begin VB.Form FrmHexView
Caption = "HexView"
ClientHeight = 3195
ClientLeft = 60
ClientTop = 345
ClientWidth = 4680
LinkTopic = "Form1"
LockControls = -1 'True
ScaleHeight = 3195
ScaleWidth = 4680
StartUpPosition = 3 '窗口缺省
Begin MSComDlg.CommonDialog CDlg1
Left = 2100
Top = 1350
_ExtentX = 847
_ExtentY = 847
_Version = 393216
CancelError = -1 'True
End
Begin RichTextLib.RichTextBox RText1
Height = 1245
Left = 0
TabIndex = 2
Top = 330
Width = 2115
_ExtentX = 3731
_ExtentY = 2196
_Version = 393217
HideSelection = 0 'False
ScrollBars = 3
DisableNoScroll = -1 'True
TextRTF = $"FrmHexView.frx":0000
End
Begin VB.TextBox TxtFile
Height = 285
Left = 570
TabIndex = 1
Text = "Text1"
ToolTipText = "文件名"
Top = 0
Width = 4035
End
Begin VB.Label Lbl1
AutoSize = -1 'True
Caption = "打开:"
Height = 180
Left = 30
TabIndex = 0
Top = 30
Width = 540
End
End
Attribute VB_Name = "FrmHexView"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)Private Sub Form_Load()
'Dim S1 As String, S2 As String * 3
'
'S1 = Space$(3)
'S2 = "03 "
'Call CopyMemory(ByVal StrPtr(S1), ByVal StrPtr(S2), 6)
'
'Debug.Print S1
CDlg1.Flags = cdlOFNFileMustExist Or cdlOFNHideReadOnly
CDlg1.Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*"
End SubPrivate Sub Form_Resize()
If Me.WindowState = 1 Then Exit Sub
On Error Resume Next
TxtFile.Width = Me.ScaleWidth - TxtFile.Left
RText1.Width = Me.ScaleWidth
RText1.Height = Me.ScaleHeight - RText1.Top
On Error GoTo 0
End SubPrivate Sub Lbl1_Click()
'
End SubPrivate Sub Lbl1_DblClick()
On Error GoTo ErrOpen
CDlg1.ShowOpen
TxtFile.Text = CDlg1.FileName
TxtFile_KeyPress vbKeyReturn
On Error GoTo 0
Exit Sub
ErrOpen:
On Error GoTo 0
End SubPrivate Sub TxtFile_Change()
'
End SubPrivate Sub TxtFile_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then
LoadHex TxtFile.Text
End If
End SubPrivate Sub LoadHex(FileStr As String)
Dim LoadBytes() As Byte
Dim FileNum As Integer
Dim FileSize As Long
Dim ArrayMax As Long
Dim AllStr As String
Dim TempStr As String
Dim TempPtr As Long
Dim I As Long
FileNum = FreeFile
On Error GoTo ErrLoad
Open TxtFile.Text For Binary Access Read Lock Write As #FileNum
On Error GoTo 0
Me.MousePointer = 13
DoEvents
FileSize = LOF(FileNum)
If FileSize <= 0 Then RText1.Text = "": Exit Sub
ArrayMax = FileSize - 1
ReDim LoadBytes(0 To ArrayMax)
Get #FileNum, , LoadBytes
Close #FileNum
AllStr = Space(FileSize * 6)
TempPtr = StrPtr(AllStr)
For I = 0 To ArrayMax
TempStr = Hex$(LoadBytes(I) \ &H10) + Hex$(LoadBytes(I) And &HF)
Call CopyMemory(ByVal TempPtr + I * 6, ByVal StrPtr(TempStr), 6)
Next I
RText1.Text = AllStr
Me.MousePointer = 0
Exit Sub
ErrLoad:
MsgBox Err.Description, vbCritical, Err.Number
End Sub
复制下列内容到记事本。保存为“HexView.vbp”。双击打开!
====================================================================
Type=Exe
Form=FrmHexView.frm
Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#..\..\..\..\..\..\WINDOWS\SYSTEM\stdole2.tlb#OLE Automation
Object={3B7C8863-D78F-101B-B9B5-04021C009402}#1.2#0; RICHTX32.OCX
Object={F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0; COMDLG32.OCX
IconForm="FrmHexView"
Startup="FrmHexView"
ExeName32="HexView.exe"
Command32=""
Name="HexView"
HelpContextID="0"
CompatibleMode="0"
MajorVer=1
MinorVer=0
RevisionVer=0
AutoIncrementVer=0
ServerSupportFiles=0
VersionCompanyName="91"
CompilationType=0
OptimizationType=0
FavorPentiumPro(tm)=0
CodeViewDebugInfo=0
NoAliasing=0
BoundsCheck=0
OverflowCheck=0
FlPointCheck=0
FDIVCheck=0
UnroundedFP=0
StartMode=0
Unattended=0
Retained=0
ThreadPerObject=0
MaxNumberOfThreads=1
复制下列内容到记事本。保存为“FrmHexView.frm”。
====================================================================
VERSION 5.00
Object = "{3B7C8863-D78F-101B-B9B5-04021C009402}#1.2#0"; "RICHTX32.OCX"
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Begin VB.Form FrmHexView
Caption = "HexView"
ClientHeight = 3195
ClientLeft = 60
ClientTop = 345
ClientWidth = 4680
LinkTopic = "Form1"
LockControls = -1 'True
ScaleHeight = 3195
ScaleWidth = 4680
StartUpPosition = 3 '窗口缺省
Begin MSComDlg.CommonDialog CDlg1
Left = 2100
Top = 1350
_ExtentX = 847
_ExtentY = 847
_Version = 393216
CancelError = -1 'True
End
Begin RichTextLib.RichTextBox RText1
Height = 1245
Left = 0
TabIndex = 2
Top = 330
Width = 2115
_ExtentX = 3731
_ExtentY = 2196
_Version = 393217
HideSelection = 0 'False
ScrollBars = 3
DisableNoScroll = -1 'True
TextRTF = $"FrmHexView.frx":0000
End
Begin VB.TextBox TxtFile
Height = 285
Left = 570
TabIndex = 1
Text = "Text1"
ToolTipText = "文件名"
Top = 0
Width = 4035
End
Begin VB.Label Lbl1
AutoSize = -1 'True
Caption = "打开:"
Height = 180
Left = 30
TabIndex = 0
Top = 30
Width = 540
End
End
Attribute VB_Name = "FrmHexView"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)Private Sub Form_Load()
'Dim S1 As String, S2 As String * 3
'
'S1 = Space$(3)
'S2 = "03 "
'Call CopyMemory(ByVal StrPtr(S1), ByVal StrPtr(S2), 6)
'
'Debug.Print S1
CDlg1.Flags = cdlOFNFileMustExist Or cdlOFNHideReadOnly
CDlg1.Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*"
End SubPrivate Sub Form_Resize()
If Me.WindowState = 1 Then Exit Sub
On Error Resume Next
TxtFile.Width = Me.ScaleWidth - TxtFile.Left
RText1.Width = Me.ScaleWidth
RText1.Height = Me.ScaleHeight - RText1.Top
On Error GoTo 0
End SubPrivate Sub Lbl1_Click()
'
End SubPrivate Sub Lbl1_DblClick()
On Error GoTo ErrOpen
CDlg1.ShowOpen
TxtFile.Text = CDlg1.FileName
TxtFile_KeyPress vbKeyReturn
On Error GoTo 0
Exit Sub
ErrOpen:
On Error GoTo 0
End SubPrivate Sub TxtFile_Change()
'
End SubPrivate Sub TxtFile_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then
LoadHex TxtFile.Text
End If
End SubPrivate Sub LoadHex(FileStr As String)
Dim LoadBytes() As Byte
Dim FileNum As Integer
Dim FileSize As Long
Dim ArrayMax As Long
Dim AllStr As String
Dim TempStr As String
Dim TempPtr As Long
Dim I As Long
FileNum = FreeFile
On Error GoTo ErrLoad
Open TxtFile.Text For Binary Access Read Lock Write As #FileNum
On Error GoTo 0
Me.MousePointer = 13
DoEvents
FileSize = LOF(FileNum)
If FileSize <= 0 Then RText1.Text = "": Exit Sub
ArrayMax = FileSize - 1
ReDim LoadBytes(0 To ArrayMax)
Get #FileNum, , LoadBytes
Close #FileNum
AllStr = Space(FileSize * 6)
TempPtr = StrPtr(AllStr)
For I = 0 To ArrayMax
TempStr = Hex$(LoadBytes(I) \ &H10) + Hex$(LoadBytes(I) And &HF)
Call CopyMemory(ByVal TempPtr + I * 6, ByVal StrPtr(TempStr), 6)
Next I
RText1.Text = AllStr
Me.MousePointer = 0
Exit Sub
ErrLoad:
MsgBox Err.Description, vbCritical, Err.Number
End Sub
复制下列内容到记事本。保存为“HexView.vbp”。双击打开!
====================================================================
Type=Exe
Form=FrmHexView.frm
Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#..\..\..\..\..\..\WINDOWS\SYSTEM\stdole2.tlb#OLE Automation
Object={3B7C8863-D78F-101B-B9B5-04021C009402}#1.2#0; RICHTX32.OCX
Object={F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0; COMDLG32.OCX
IconForm="FrmHexView"
Startup="FrmHexView"
ExeName32="HexView.exe"
Command32=""
Name="HexView"
HelpContextID="0"
CompatibleMode="0"
MajorVer=1
MinorVer=0
RevisionVer=0
AutoIncrementVer=0
ServerSupportFiles=0
VersionCompanyName="91"
CompilationType=0
OptimizationType=0
FavorPentiumPro(tm)=0
CodeViewDebugInfo=0
NoAliasing=0
BoundsCheck=0
OverflowCheck=0
FlPointCheck=0
FDIVCheck=0
UnroundedFP=0
StartMode=0
Unattended=0
Retained=0
ThreadPerObject=0
MaxNumberOfThreads=1