Me.Text
成都创新互联始终坚持【策划先行,效果至上】的经营理念,通过多达十余年累计超上千家客户的网站建设总结了一套系统有效的网络营销推广解决方案,现已广泛运用于各行各业的客户,其中包括:成都集装箱等企业,备受客户赞美。
例如:MsgBox(Me.Text)
或者:窗体名.Text
例如: MsgBox(Form1.Text)
' .NET 的数据类型和 VB6 的完全不同。API 声明也完全不一样。
Private Declare Function WindowFromPoint Lib "user32" Alias "WindowFromPoint" (ByVal xPoint As Integer, ByVal yPoint As Integer) As IntPtr
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As IntPtr) As Integer
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As IntPtr, ByVal lpString As String, ByVal cch As Integer) As Integer
Private Structure TitleEXD
VBFixedString(255) Public Text As String
End Structure
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim x As Integer = MousePosition.X, y As Integer = MousePosition.Y, res As String
Label1.Text = "鼠标当前坐标:" x "," y
Dim hwnd As IntPtr = WindowFromPoint(x, y)
Label2.Text = "句柄:" hwnd.ToString()
Dim Tlong As Integer = GetWindowTextLength(hwnd) Mod 65536 + 1
Dim TitleE As TitleEXD
TitleE.Text = Space(255)
Dim dlld As Integer = GetWindowText(Me.Handle, TitleE.Text, Tlong) Mod 65536
Label3.Text = "窗口标题:" TitleE.Text
If dlld = 0 Then
res = "失败"
Else
res = "成功"
End If
Label4.Text = "获取标题" res
End Sub
利用Process类遍历当前所有进程,利用MainWindowTitle属性来获取指定窗口标题的进程ID,创建一个线程池或者线程,来循环检测这个ID的进程是否已退出,在循环线程中设置Thread.Sleep(50)中断来减少系统开销,这个方法仅适用于主窗口,也就是窗体关闭,程序就退出了,如果针对的是子窗口,就用第二种方法。
利用系统API,循环遍历所有窗口,当指定标题不存在时就是已经退出了。