帮忙看看控制端的代码
Option Explicit
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
' 本函数的功能是设定窗体是否总在最前端
Const SWP_NOSIZE = &H1
Const SWP_NOMOVE = &H2
Const HWND_NOTOPMOST = -2
Const HWND_TOPMOST = -1
Const Flags = SWP_NOSIZE + SWP_NOMOVE
Dim LastData As String '定义 LastData 用来判断,前后两个网址,是否为一样的
Private Sub Form_Load()
SetWindowPos hwnd, HWND_TOPMOST, 0, 0, 0, 0, Flags '将窗口置于最上面
SeekClient.RemotePort = 1999 '初始化Winsock控件的远程端口
SeekClient.LocalPort = 1998 '初始化Winsock控件的本地端口
SeekClient.Listen '进行远程连接
Open App.Path & "\TestFile.txt" For Output Access Write As #1 '打开磁盘文件并且赋予Id号为1
LastData = "" '初始化 LastData 为空字符串
MsgBox "请在关闭被监控端程序窗口前,关闭本程序"
End Sub
Private Sub Form_Unload(Cancel As Integer)
SeekClient.Close '关闭 Winsock 控件的服务能力
SetWindowPos hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, Flags '停止本窗体一直在最前端
Close #1 ' 关闭磁盘文件
End Sub
Private Sub mnuAbout_Click()
frmAbout.Show 1
End Sub
Private Sub mnuCreat_Click()
MsgBox "在此处添加新建监控的电脑的IP地址"
End Sub
Private Sub SeekClient_Close()
SeekClient.Close
SeekClient.Listen
End Sub
Private Sub SeekClient_ConnectionRequest(ByVal requestID As Long)
If SeekClient.State <> sckClosed Then
SeekClient.Close '检查控件的 State 属性是否为关闭的。
End If '如果不是,在接受新的连接之前先关闭此连接。
SeekClient.Accept requestID 'Winsock 控件开始接受
End Sub
Private Sub SeekClient_DataArrival(ByVal bytesTotal As Long)
Dim strData As String
SeekClient.GetData strData '获得远程传送的数据流
If strData <> LastData Then
LstURL.AddItem strData
Write #1, strData ' 写入磁盘文件中
LastData = strData
End If
End Sub
Option Explicit
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
' 本函数的功能是设定窗体是否总在最前端
Const SWP_NOSIZE = &H1
Const SWP_NOMOVE = &H2
Const HWND_NOTOPMOST = -2
Const HWND_TOPMOST = -1
Const Flags = SWP_NOSIZE + SWP_NOMOVE
Dim LastData As String '定义 LastData 用来判断,前后两个网址,是否为一样的
Private Sub Form_Load()
SetWindowPos hwnd, HWND_TOPMOST, 0, 0, 0, 0, Flags '将窗口置于最上面
SeekClient.RemotePort = 1999 '初始化Winsock控件的远程端口
SeekClient.LocalPort = 1998 '初始化Winsock控件的本地端口
SeekClient.Listen '进行远程连接
Open App.Path & "\TestFile.txt" For Output Access Write As #1 '打开磁盘文件并且赋予Id号为1
LastData = "" '初始化 LastData 为空字符串
MsgBox "请在关闭被监控端程序窗口前,关闭本程序"
End Sub
Private Sub Form_Unload(Cancel As Integer)
SeekClient.Close '关闭 Winsock 控件的服务能力
SetWindowPos hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, Flags '停止本窗体一直在最前端
Close #1 ' 关闭磁盘文件
End Sub
Private Sub mnuAbout_Click()
frmAbout.Show 1
End Sub
Private Sub mnuCreat_Click()
MsgBox "在此处添加新建监控的电脑的IP地址"
End Sub
Private Sub SeekClient_Close()
SeekClient.Close
SeekClient.Listen
End Sub
Private Sub SeekClient_ConnectionRequest(ByVal requestID As Long)
If SeekClient.State <> sckClosed Then
SeekClient.Close '检查控件的 State 属性是否为关闭的。
End If '如果不是,在接受新的连接之前先关闭此连接。
SeekClient.Accept requestID 'Winsock 控件开始接受
End Sub
Private Sub SeekClient_DataArrival(ByVal bytesTotal As Long)
Dim strData As String
SeekClient.GetData strData '获得远程传送的数据流
If strData <> LastData Then
LstURL.AddItem strData
Write #1, strData ' 写入磁盘文件中
LastData = strData
End If
End Sub