VB程序设计-----模拟监控程序

VB程序设计-----模拟监控程序,第1张

Dim Cnt As Integer '计数

Dim Tmp As Integer '随机点

Dim JX As Integer '画点间距

Private Sub Form_Load()

JX = 2

End Sub

Private Sub Timer1_Timer()

Dim Lin As Integer

Dim V1, V2 As Integer

lbNow = Now

'采集数据

Lin = txtData.Text

V1 = (300 - Lin) \ 2 - 5

Randomize

Tmp = Int(Rnd * 200 + 100)

txtData.Text = Tmp

V2 = (300 - Tmp) \ 2 - 5

'采集时间

Cnt = Cnt + 1

txtTime.Text = Cnt

'画坐标

picData.Line (0, 5)-(250, 5), vbRed '280

picData.Line (0, 20)-(250, 20), vbRed '250

picData.Line (0, 35)-(250, 35), vbBlue '220

picData.Line (0, 50)-(250, 50), vbBlue '190

picData.Line (0, 65)-(250, 65), vbBlue '160

picData.Line (0, 80)-(250, 80), vbBlue '130

picData.Line (0, 95)-(250, 95), vbBlue '100

'画图

picData.Line (JX * Cnt, V2)-(JX * Cnt - 1, V1), vbBlack

End Sub

如需源代码可以发给你。

以记事本为例

Public Class Form1

Public Sub ShellAndWait(ByVal ProcessPath As String)

Dim objProcess As System.Diagnostics.Process

Try

objProcess = New System.Diagnostics.Process()

objProcess.StartInfo.FileName = ProcessPath

objProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal

objProcess.Start()

objProcess.WaitForExit()

objProcess.Close()

Catch

MessageBox.Show("无法执行文件 " &ProcessPath, "错误")

End Try

End Sub

'监视程序就可以了,若果监视别的窗体的话,用SPY++ 找到句柄,配合FindWindowEx,SendMessage根据其属性做

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

ShellAndWait("Notepad.exe")

MessageBox.Show("笔记本被关闭后我才会出现")

End Sub

End Class

VB6 方法1调用API

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _

(ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Declare Function IsWindow Lib "user32" (ByVal hwnd As Long) As Long

Dim lngAns As Long

lngAns = FindWindow(vbNullString, "窗体的CAPTION")

lngAns = IsWindow(lngAns)

If lngAns <> 0 Then

MsgBox "窗体已经被加载!", vbOKOnly

End

Else

MsgBox "窗体未被加载!", vbOKOnly

End If

VB6 方法2 Dim frm As Object

Dim blnFlag As Boolean

For Each frm In Forms

If frm.Caption = "FORM标题" Then

blnFlag = True

Exit For

End If

Next frm

If blnFlag Then

MsgBox "Form已经加载"

Else

MsgBox "Form未加载"

End If VB.NET的代码 (简单的需改,VB6也可以运行)Public Function midchi(ByVal frmName As String) As Boolean

Dim chiFrm As Windows.Forms.Form

For Each chiFrm In Me.MdiChildren

If chiFrm.Name = frmName Then

If chiFrm.Visible Then

chiFrm.Activate()

Else

chiFrm.Show()

End If

Return True

End If

Next

Return False

End FunctionPrivate Sub MenuItem7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem7.Click

If midchi("frmComputer") Then

Exit Sub

End If

Dim frmCp As New frmComputer

frmCp.MdiParent = Me

frmCp.Show()

End Sub


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/11304710.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-15
下一篇 2023-05-15

发表评论

登录后才能评论

评论列表(0条)

保存