1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
<DllImport("User32.dll", SetLastError:=True, CharSet:=CharSet.Auto)>
Private Shared Function GetClassName(hwnd As IntPtr, lpClassName As StringBuilder, nMaxCount As Long) As Long
End Function
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)>
Private Shared Function GetWindowTextLength(hWnd As IntPtr) As Integer
End Function
<DllImport("user32.dll")>
Private Shared Function GetWindowText(ByVal hWnd As IntPtr, ByVal lpString As StringBuilder, ByVal nMaxCount As Integer) As Integer
End Function
Private Function CaptionFromHandle(hwnd As IntPtr) As String
Dim cName As String = String.Empty
Dim cText As StringBuilder = Nothing
Try
Dim cLength As Integer = GetWindowTextLength(hwnd)
cText = New StringBuilder(String.Empty, cLength + 5)
GetWindowText(hwnd, cText, cLength + 2)
If Not String.IsNullOrEmpty(cText.ToString()) AndAlso
Not String.IsNullOrWhiteSpace(cText.ToString()) Then
cName = cText.ToString()
End If
Catch ex As Exception
cName = ex.Message
Finally
cText = Nothing
End Try
Return cName
End Function
Private Function ClassNameFromHandle(hwnd As IntPtr) As String
Dim cName As String = String.Empty
Dim cText As StringBuilder = Nothing
Try
Dim cLength As Integer = 1000
cText = New StringBuilder(String.Empty, cLength + 5)
GetClassName(hwnd, cText, cLength + 2)
If Not String.IsNullOrEmpty(cText.ToString()) AndAlso
Not String.IsNullOrWhiteSpace(cText.ToString()) Then
cName = cText.ToString()
End If
Catch ex As Exception
cName = ex.Message
Finally
cText = Nothing
End Try
Return cName
End Function |
Partager