我需要一个vb编写的记事本的工程,不要exe哦~~
拜托,帮帮忙~~
我需要一个vb编写的记事本的工程,不要exe哦~~
拜托,帮帮忙~~
'记事本代码是很长的 ^_^
'窗体代码
Option Explicit
Dim filename As String
Dim FileType As String
Dim FiType As String
Dim sFind As String
Dim result As String
Dim bWrap As Boolean
Dim ask As Boolean
Dim msgtext As String
Dim Flag As String
Private Sub Form_Load()
ask = False
RichText.Text = ""
filename = "无标题-记事本"
Form1.Caption = "无标题-记事本"
RichText.Height = Form1.ScaleHeight
RichText.Width = Form1.ScaleWidth
StatusBar1.Visible = False
StatusBar1.Panels(1).Text = Time
mnucopy.Enabled = False
mnucut.Enabled = False
mnufound.Enabled = False
mnufoundnext.Enabled = False
mnudel.Enabled = False
mnucancel.Enabled = False
mnuwordwrap.Checked = True
mnugoto.Enabled = False
If Clipboard.GetText <> "" Then
mnuplaster.Enabled = True
Else
mnuplaster.Enabled = False
End If
App.HelpFile = App.Path & "\notepad.chm"
End Sub
Private Sub Form_Resize()
RichText.Height = Form1.ScaleHeight
RichText.Width = Form1.ScaleWidth
End Sub
Private Sub Form_Unload(Cancel As Integer)
msgtext = "文件" & filename & "的文字已经改变。" & Chr(10) & Chr(13) & "想保存文件吗?"
If ask = True Then
Flag = MsgBox(msgtext, 35, "记事本") ' 35=32+3
If Flag = vbYes Then mnusave_Click '选择了确定则保存之
If Flag = vbCancel Then Cancel = True
If Flag = vbNo Then Unload Me
End If
End Sub
Private Sub mnuabout_Click()
MsgBox "记事本", vbOKOnly, "关于"
End Sub
Private Sub mnuall_Click()
RichText.SelStart = 0
RichText.SelLength = Len(RichText.Text)
End Sub
Private Sub mnucancel_Click()
MsgBox "请点击鼠标右键撤销!", vbOKOnly, "提示"
End Sub
Private Sub mnucopy_Click()
Clipboard.Clear
Clipboard.SetText RichText.SelText
End Sub
Private Sub mnucut_Click()
Clipboard.Clear
Clipboard.SetText RichText.SelText
RichText.SelText = ""
End Sub
Private Sub mnudel_Click()
RichText.SelText = ""
End Sub
Private Sub mnuedit_Click()
If RichText.SelText <> "" Then
mnuopen.Enabled = True
mnucut.Enabled = True
mnudel.Enabled = True
mnucopy.Enabled = True
End If
If Len(RichText.Text) <> 0 Then
mnufound.Enabled = True
mnufoundnext.Enabled = True
End If
If ask = True Then mnucancel.Enabled = True
End Sub
Private Sub mnuexit_Click()
Unload Me
End Sub
Private Sub mnufont_Click()
On Error Resume Next
CommonDialog1.flags = &H3 Or &H1 Or &H2 Or &H100
CommonDialog1.Action = 4
RichText.Font.Name = CommonDialog1.FontName
RichText.Font.Size = CommonDialog1.FontSize
RichText.Font.Bold = CommonDialog1.FontBold
RichText.Font.Italic = CommonDialog1.FontItalic
RichText.Font.Underline = CommonDialog1.FontUnderline
RichText.SelColor = CommonDialog1.Color
End Sub
Private Sub mnufound_Click()
sFind = InputBox("请输入要查找的字、词:", "查找内容", sFind)
RichText.Find sFind
End Sub
Private Sub mnufoundnext_Click()
RichText.SelStart = RichText.SelStart + RichText.SelLength + 1
RichText.Find sFind, , Len(RichText)
End Sub
Private Sub mnuhelptopic_Click()
SendKeys "{F1}"
End Sub
Private Sub mnunewfile_Click()
On Error Resume Next
Dim n As Integer
msgtext = "文件" & filename & "的文字已经改变。" & Chr(10) & Chr(13) & "想保存文件吗?"
If Len(RichText.Text) <> 0 Then
If filename = "无标题-记事本" Then
Flag = MsgBox(msgtext, 35, "记事本") '给予提示
If Flag = vbYes Then
mnusaveas_Click
RichText.Text = ""
Form1.Caption = "无标题-记事本"
filename = "无标题-记事本"
End If
If Flag = vbCancel Then Exit Sub
If Flag = vbNo Then
RichText.Text = ""
Form1.Caption = "无标题-记事本"
filename = "无标题-记事本"
End If
End If
End If
End Sub
Private Sub mnuopen_Click()
msgtext = "文件" & filename & "的文字已经改变。" & Chr(10) & Chr(13) & "想保存文件吗?"
On Error Resume Next
If ask = True Then
Flag = MsgBox(msgtext, 35, "记事本") '给予提示
If Flag = vbYes Then mnusave_Click '选择了确定则保存之
If Flag = vbCancel Then Exit Sub
If Flag = vbNo Then GoTo L1
End If
ask = False
L1: CommonDialog1.Filter = "文本文档(*.txt)|*.txt|RTF文档(*.rtf)|*.rtf|所有文件(*.*)|*.*"
CommonDialog1.ShowOpen
RichText.Text = "" '清空文本框
filename = CommonDialog1.filename
RichText.LoadFile filename
result = GetFileTitle(filename)
Me.Caption = "" & result & "-记事本"
End Sub
Private Sub mnupagesetup_Click()
psdlg.lStructSize = Len(psdlg)
psdlg.hwndOwner = hwnd
PageSetupDlg psdlg
End Sub
Private Sub mnuplaster_Click()
RichText.SelText = Clipboard.GetText(1)
End Sub
Private Sub mnuprint_Click()
Dim f As Integer, t As Integer
Dim i As Integer
CommonDialog1.CancelError = True
CommonDialog1.Max = 1000
CommonDialog1.Min = 1
On Error Resume Next
CommonDialog1.ShowPrinter
For f = CommonDialog1.FromPage To t = CommonDialog1.ToPage
Do While i < CommonDialog1.Copies + 1
Printer.Print RichText.Text
i = i + 1
Loop
Next
Printer.EndDoc
Cancel:
If Err.Number = 32755 Then
Exit Sub
End If
End Sub
Private Sub mnusave_Click()
CommonDialog1.Filter = "文本文档(*.txt)|所有文件(*.*)|*.*"
On Error Resume Next
filename = CommonDialog1.filename '保存文件
If filename <> "" Then
RichText.SaveFile filename, rtfText
Else
mnusaveas_Click
End If
ask = False
End Sub
Private Sub mnusaveas_Click()
CommonDialog1.Filter = "文本文档(*.txt)|所有文件(*.*)|*.*"
On Error Resume Next
CommonDialog1.ShowSave
filename = CommonDialog1.filename
RichText.SaveFile filename, rtfText
result = GetFileTitle(filename)
Me.Caption = "" & result & "-记事本"
ask = False
End Sub
Private Sub mnustatusbar_Click()
If mnustatusbar.Checked Then
StatusBar1.Visible = False
mnustatusbar.Checked = False
Else
StatusBar1.Visible = True
mnustatusbar.Checked = True
End If
End Sub
Private Sub mnutimedate_Click()
RichText.SelText = Format(Now, "h:mm ddddd")
End Sub
Private Sub mnuwordwrap_Click()
WrapTextLine RichText, bWrap
bWrap = Not bWrap
If mnuwordwrap.Checked = False Then
HScroll1.Enabled = True
mnuwordwrap.Checked = True
Else
HScroll1.Enabled = False
mnuwordwrap.Checked = False
End If
End Sub
Private Sub RichText_Change()
ask = True
End Sub
Private Sub Timer1_Timer()
If StatusBar1.Panels(1).Text <> CStr(Time) Then
StatusBar1.Panels(1).Text = Time
End If
End Sub
'模块代码
Option Explicit
Const WM_USER = &H400
Const EM_SETTARGETDEVICE = (WM_USER + 72)
Type POINTAPI
x As Long
y As Long
End Type
Type RECT
left As Long
right As Long
top As Long
bottom As Long
End Type
Public Type PageSetupDlg
lStructSize As Long
hwndOwner As Long
hDevMode As Long
hDevNames As Long
flags As Long
ptPaperSize As POINTAPI
rtMinMargin As RECT
rtMargin As RECT
hInstance As Long
lCustData As Long
lpfnPageSetupHook As Long
lpfnPagePaintHook As Long
lpPageSetupTemplateName As String
hPageSetupTemplate As Long
End Type
Public psdlg As PageSetupDlg
Declare Function PageSetupDlg Lib "comdlg32.dll" Alias "PageSetupDlgA" (pPagesetupdlg As PageSetupDlg) As Long
Public Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Dim bWrap As Boolean '// 换行标记'// 自定义一个换行的过程
Public Sub WrapTextLine(ByRef RichText As RichTextBox, ByVal bWrapSwitch As Boolean)
On Error Resume Next
If bWrapSwitch Then '// 设置 RichTextBox 自动换行
SendMessage RichText.hwnd, EM_SETTARGETDEVICE, GetDC(RichText.hwnd), RichText.Width / 15
RichText.RightMargin = IIf(RichText.RightMargin = 0, 1, 0)
Else
'// 设置 RichTextBox 不自动换行
SendMessage RichText.hwnd, EM_SETTARGETDEVICE, 0, 1
End If
End Sub
Function GetFileTitle(OldStr As String) As String
On Error Resume Next
Dim n As Integer, m As Integer '声明字符串变量
Dim i As String, r As String
Dim p As Integer
i = "\" '要查找的指定字符
For n = 1 To Len(OldStr) '用Len函数计算已知字符串的字节数
m = InStrRev(OldStr, i, -1) '"\"所在的位置(其中的-1是默认的)
Next n '找下去!
'截取最后一个"\"后面的字符串
r = right(OldStr, Len(OldStr) - m) '获取Title
p = InStrRev(r, ".", -1) '"."所在位置
GetFileTitle = left(r, p - 1) '去掉后缀
End Function