Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Type POINTAPI '定义点(Point)结构
x As Long '点在X坐标(横坐标)上的坐标值
y As Long '点在Y坐标(纵坐标)上的坐标值
End Type
Dim WithEvents Timer1 As Timer ' 这里定义钩住事件
Dim MousePoint As POINTAPI
Private Sub Form_Load()
'创建一个计时器
Set Timer1 = Form1.Controls.Add("VB.Timer", "Timer1", Me)
'时间设置
Timer1.Interval = 1
Timer1.Enabled = True
If Dir(App.Path & "\Log.txt") <> "" Then
Open App.Path & "\Log.txt" For Input As #1
Dim s As String
Input #1, s
Text1.Text = s
Close #1
End If
End Sub
完整代码如下,请在窗体上添加一个Text控件测试:
Private Sub Form_Load()
Dim SaveTXT As String
SaveTXT = GetSetting("VB", "MYAPP", "SaveTXT")
If SaveTXT <> "" Then
Text1.Text = SaveTXT
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
SaveSetting "VB", "MYAPP", "SaveTXT", Text1.Text
End Sub
可以将修改后的内容保存到文本文件或数据库。下次启动程序时从文本文件或数据库中取出来