vb.net设置windows焦点程序
RT,我想让vb.net控制windows的焦点,切换到指定程序并焦点在这个程序之上供用户使用,有没有什么办法(比如打开了ie,按某个按扭就切换到已打开的IE),谢谢了...
RT,我想让vb.net 控制windows的焦点,切换到指定程序并焦点在这个程序之上供用户使用,有没有什么办法(比如打开了ie,按某个按扭就切换到已打开的IE),谢谢了
展开
2个回答
展开全部
给你个参考的例子,窗体打开时可能大小有变化,软件名可能有变化
先加个控件ListBox1,运行后双击ListBox1上程序名
Public Class Form1
Public myProcess() As Process
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim myProcesses() As Process = Process.GetProcesses()
Dim jh As New ArrayList
For Each bs As Process In myProcesses
If CInt(bs.MainWindowHandle) > 0 Then
ListBox1.Items.Add(bs.ProcessName)
jh.Add(bs)
End If
Next
ReDim myProcess(jh.Count - 1)
jh.CopyTo(myProcess)
End Sub
Declare Function ShowWindow Lib "user32" Alias "ShowWindow" (ByVal hwnd As Integer, ByVal nCmdShow As Long) As Integer
Private Sub ListBox1_MouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseDoubleClick
Dim a As Process = myProcess(ListBox1.SelectedIndex)
Try
Dim dd = ShowWindow(a.MainWindowHandle, &H1)
AppActivate(a.Id)
Catch ex As Exception
End Try
End Sub
End Class
先加个控件ListBox1,运行后双击ListBox1上程序名
Public Class Form1
Public myProcess() As Process
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim myProcesses() As Process = Process.GetProcesses()
Dim jh As New ArrayList
For Each bs As Process In myProcesses
If CInt(bs.MainWindowHandle) > 0 Then
ListBox1.Items.Add(bs.ProcessName)
jh.Add(bs)
End If
Next
ReDim myProcess(jh.Count - 1)
jh.CopyTo(myProcess)
End Sub
Declare Function ShowWindow Lib "user32" Alias "ShowWindow" (ByVal hwnd As Integer, ByVal nCmdShow As Long) As Integer
Private Sub ListBox1_MouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseDoubleClick
Dim a As Process = myProcess(ListBox1.SelectedIndex)
Try
Dim dd = ShowWindow(a.MainWindowHandle, &H1)
AppActivate(a.Id)
Catch ex As Exception
End Try
End Sub
End Class
追问
我试下,谢谢 不知道对根据进程名或是窗口的标题名.
微测检测5.10
2023-05-10 广告
2023-05-10 广告
您好!建议咨 深圳市微测检测有限公司,已建立起十余个专业实验室,企业通过微测检测就可以获得一站式的测试与认 证解决方案;(EMC、RF、MFi、BQB、QI、USB、安全、锂电池、快充、汽车电子EMC、汽车手机互 联、语音通话质量),认证遇...
点击进入详情页
本回答由微测检测5.10提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询