VB.NET FindWindow exe窗体类型
时间: 2023-11-27 07:49:27 浏览: 46
在 VB.NET 中,可以使用 `FindWindow` 函数来查找指定窗口的句柄。要查找特定类型的窗口,可以使用窗口类名作为函数的第二个参数。对于 exe 程序的窗口,其窗口类名通常为 `WindowsForms10.Window.8.app.*`,其中 `*` 表示具体的程序名称。
下面是使用 `FindWindow` 函数查找 exe 程序窗口句柄的示例代码:
```vb.net
Imports System.Runtime.InteropServices
Public Class Form1
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)>
Private Shared Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
End Function
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim hWnd As IntPtr = FindWindow("WindowsForms10.Window.8.app.*", "窗口标题")
If hWnd <> IntPtr.Zero Then
MessageBox.Show("找到窗口句柄:" & hWnd.ToString())
Else
MessageBox.Show("未找到窗口")
End If
End Sub
End Class
```
在上面的示例中,`FindWindow` 函数被声明为 `DllImport`,以便在 VB.NET 中调用 Windows API 函数。在单击按钮时,调用 `FindWindow` 函数并传递窗口类名和窗口标题作为参数。如果找到窗口,则显示窗口句柄,否则显示未找到窗口的消息框。
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![xlsx](https://img-home.csdnimg.cn/images/20210720083732.png)