大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
两个方法
富拉尔基ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:18982081108(备注:SSL证书合作)期待与您的合作!
1.
要接收的窗口先使用FindWindow这个api获得句柄
调用SetForegroundWindow使其获得焦点并选中
调用.net方法:SendKeys.Send方法发送
2.使用API的SendInput
这样的话你就不要直接把子窗口show出来,先在父窗口创建一个子窗口对象的变量,通过实例化该变量达到创建子窗口的目的,然后在下次又要打开子窗口时也可以通过该变量关闭原有的子窗口
示例代码如下(假设Form1为父窗口,Form2为子窗口):
Form1的代码:
Public
Class
Form1
Dim
nform
As
Form2
=
Nothing
Private
Sub
Button1_Click(ByVal
sender
As
System.Object,
ByVal
e
As
System.EventArgs)
Handles
Button1.Click
If
nform
IsNot
Nothing
Then
nform.Close()
nform.Dispose()
End
If
nform
=
New
Form2
nform.Show()
Me.Hide()
End
Sub
End
Class
通过nform变量,你可以很轻易就处理掉原来已经打开但隐藏着的子窗口了
使用wmi
类“Win32_Processor”中LoadPercentage属性为当前的cpu使用率
示例代码: Private Sub Timer1_Timer()
Dim WMI服务 As Object
Dim 对象 As Object
Dim 子对象 As Object
Dim 电脑名 As String
Dim 刷新 As Long
刷新 = 0
电脑名 = "." '表示本地计算机
Set WMI服务 = GetObject("winmgmts://" 电脑名 "/root/cimv2")
Set 对象 = WMI服务.InstancesOf("Win32_Processor")
Me.CurrentX = 0
Me.CurrentY = 0
For Each 子对象 In 对象
If 刷新 = 0 Then
刷新 = 1
Me.Cls
End If
Me.Print 子对象.Name "[" 子对象.CurrentClockSpeed "Hz] 使用率:" _
子对象.LoadPercentage "%"
Next
End Sub
好像不难吧?
我放进了Button1的Click事件里。
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
On Error GoTo Errmessages '在做系统操作时加排错标签是个好习惯
Dim TargetName As String = "ibmdict" '存储进程名为文本型,注:进程名不加扩展名
Dim TargetKill() As Process = Process.GetProcessesByName(TargetName) '从进程名获取进程
Dim TargetPath As String '存储进程路径为文本型
If TargetKill.Length 1 Then '判断进程名的数量,如果同名进程数量在2个以上,用For循环关闭进程。
For i = 0 To TargetKill.Length - 1
TargetPath = TargetKill(i).MainModule.FileName
TargetKill(i).Kill()
Next
ElseIf TargetKill.Length = 0 Then '判断进程名的数量,没有发现进程直接弹窗。不需要的,可直接删掉该If子句
MsgBox("没有发现进程!")
Exit Sub
ElseIf TargetKill.Length = 1 Then '判断进程名的数量,如果只有一个,就不用For循环
TargetKill(0).Kill()
End If
MsgBox("已终止" TargetKill.Length "个进程") '弹窗提示已终止多少个进程
Errmessages: ‘定义排错标签
If Err.Description Nothing Then ’判断有无错误,如果有,则 ↓
MsgBox(Err.Description) '当出现错误时,弹窗提示
End If
End Sub
可根据需要自行修改,这个备注够完善了吧?不会的再Hi我。
下面的代码示例说明了更改线程优先级的结果。创建两个线程,其中一个线程的优先级设置为 BelowNormal。两个线程在 while 循环中都增加一个变量,并运行一段设定的时间。
Option Explicit
Option Strict
Imports System
Imports System.Threading
Public Class Test
MTAThread _
Shared Sub Main()
Dim priorityTest As New PriorityTest()
Dim threadOne As Thread = _
New Thread(AddressOf priorityTest.ThreadMethod)
threadOne.Name = "ThreadOne"
Dim threadTwo As Thread = _
New Thread(AddressOf priorityTest.ThreadMethod)
threadTwo.Name = "ThreadTwo"
threadTwo.Priority = ThreadPriority.BelowNormal
threadOne.Start()
threadTwo.Start()
' Allow counting for 10 seconds.
Thread.Sleep(10000)
priorityTest.LoopSwitch = False
End Sub
End Class
Public Class PriorityTest
Dim loopSwitchValue As Boolean
Sub New()
loopSwitchValue = True
End Sub
WriteOnly Property LoopSwitch As Boolean
Set
loopSwitchValue = Value
End Set
End Property
Sub ThreadMethod()
Dim threadCount As Long = 0
While loopSwitchValue
threadCount += 1
End While
Console.WriteLine("{0} with {1,11} priority " _
"has a count = {2,13}", Thread.CurrentThread.Name, _
Thread.CurrentThread.Priority.ToString(), _
threadCount.ToString("N0"))
End Sub
End Class
试试看这样行不:在应用程序设置中,勾选“生成单个实例应用程序”,然后在应用程序事件中处理这个事件
Private Sub MyApplication_StartupNextInstance(sender As Object, e As StartupNextInstanceEventArgs) Handles Me.StartupNextInstance
'这里的 e.CommandLine应该就是双击第二个文件时传进来的命令行
End Sub