GetWindowText() 不适用于希腊语
GetWindowText() Doesn't Work For Greek
我正在使用此代码获取打开的列表 windows:
Delegate Function EnumWindowDelegate(ByVal hWnd As IntPtr, ByVal Lparam As IntPtr) As Boolean
Private Callback As EnumWindowDelegate = New EnumWindowDelegate(AddressOf EnumWindowProc)
Private Function EnumWindowProc(ByVal hWnd As IntPtr, ByVal Lparam As IntPtr) As Boolean
If IsWindowVisible(hWnd) Then
Dim TheLength As Integer = GetWindowTextLengthA(hWnd)
Dim TheReturn(TheLength * 2) As Byte
GetWindowText(hWnd, TheReturn, TheLength + 1)
Dim TheText As String = ""
For x = 0 To (TheLength - 1) * 2
If TheReturn(x) <> 0 Then
TheText &= Chr(TheReturn(x))
End If
Next
If TheText <> "" Then
ListBox1.Items.Add(TheText & " (" & CStr(hWnd) & ")")
End If
End If
Return True
End Function
Private Declare Function EnumWindows Lib "User32.dll" (ByVal WNDENUMPROC As EnumWindowDelegate, ByVal lparam As IntPtr) As Boolean
Private Declare Auto Function GetWindowText Lib "User32.dll" (ByVal Hwnd As IntPtr, ByVal Txt As Byte(), ByVal Lng As Integer) As Integer
Private Declare Function IsWindowVisible Lib "User32.dll" (ByVal hwnd As IntPtr) As Boolean
Private Declare Function GetWindowTextLengthA Lib "User32.dll" (ByVal hwnd As IntPtr) As Integer
用法:EnumWindows(Callback, IntPtr.Zero)
它可以工作 但是 如果打开带有希腊标题的 window ex。 'Мουσική' 此代码输出 'œ¿Åùº® '。如您所见,出了点问题。有办法解决这个问题吗?
P.S。抱歉我的英语不好:)
好的,我想我找到了解决方案:使用 GetWindowTextA 而不是 GetWindowText。
@Trevor 在问题的评论中提出了这个建议,我试过了但没有用。不知何故,我设法让它发挥作用。
感谢所有试图提供帮助的人:)。这是工作代码:
Delegate Function EnumWindowDelegate(ByVal hWnd As IntPtr, ByVal Lparam As IntPtr) As Boolean
Private Callback As EnumWindowDelegate = New EnumWindowDelegate(AddressOf EnumWindowProc)
Private Function EnumWindowProc(ByVal hWnd As IntPtr, ByVal Lparam As IntPtr) As Boolean
If IsWindowVisible(hWnd) Then
Dim TheLength As Integer = GetWindowTextLengthA(hWnd)
Dim TheReturn(TheLength * 2) As Byte
GetWindowText(hWnd, TheReturn, TheLength + 1)
Dim TheText As String = ""
For x = 0 To (TheLength - 1) * 2
If TheReturn(x) <> 0 Then
TheText &= Chr(TheReturn(x))
End If
Next
If Not TheText = "" Then
ListBox1.Items.Add(TheText & " (" & CStr(hWnd) & ")")
End If
End If
Return True
End Function
Private Declare Function EnumWindows Lib "User32.dll" (ByVal WNDENUMPROC As EnumWindowDelegate, ByVal lparam As IntPtr) As Boolean
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal Hwnd As IntPtr, ByVal Txt As Byte(), ByVal Lng As Integer) As Integer
Private Declare Function IsWindowVisible Lib "User32.dll" (ByVal hwnd As IntPtr) As Boolean
Private Declare Function GetWindowTextLengthA Lib "User32.dll" (ByVal hwnd As IntPtr) As Integer
我正在使用此代码获取打开的列表 windows:
Delegate Function EnumWindowDelegate(ByVal hWnd As IntPtr, ByVal Lparam As IntPtr) As Boolean
Private Callback As EnumWindowDelegate = New EnumWindowDelegate(AddressOf EnumWindowProc)
Private Function EnumWindowProc(ByVal hWnd As IntPtr, ByVal Lparam As IntPtr) As Boolean
If IsWindowVisible(hWnd) Then
Dim TheLength As Integer = GetWindowTextLengthA(hWnd)
Dim TheReturn(TheLength * 2) As Byte
GetWindowText(hWnd, TheReturn, TheLength + 1)
Dim TheText As String = ""
For x = 0 To (TheLength - 1) * 2
If TheReturn(x) <> 0 Then
TheText &= Chr(TheReturn(x))
End If
Next
If TheText <> "" Then
ListBox1.Items.Add(TheText & " (" & CStr(hWnd) & ")")
End If
End If
Return True
End Function
Private Declare Function EnumWindows Lib "User32.dll" (ByVal WNDENUMPROC As EnumWindowDelegate, ByVal lparam As IntPtr) As Boolean
Private Declare Auto Function GetWindowText Lib "User32.dll" (ByVal Hwnd As IntPtr, ByVal Txt As Byte(), ByVal Lng As Integer) As Integer
Private Declare Function IsWindowVisible Lib "User32.dll" (ByVal hwnd As IntPtr) As Boolean
Private Declare Function GetWindowTextLengthA Lib "User32.dll" (ByVal hwnd As IntPtr) As Integer
用法:EnumWindows(Callback, IntPtr.Zero)
它可以工作 但是 如果打开带有希腊标题的 window ex。 'Мουσική' 此代码输出 'œ¿Åùº® '。如您所见,出了点问题。有办法解决这个问题吗?
P.S。抱歉我的英语不好:)
好的,我想我找到了解决方案:使用 GetWindowTextA 而不是 GetWindowText。
@Trevor 在问题的评论中提出了这个建议,我试过了但没有用。不知何故,我设法让它发挥作用。
感谢所有试图提供帮助的人:)。这是工作代码:
Delegate Function EnumWindowDelegate(ByVal hWnd As IntPtr, ByVal Lparam As IntPtr) As Boolean
Private Callback As EnumWindowDelegate = New EnumWindowDelegate(AddressOf EnumWindowProc)
Private Function EnumWindowProc(ByVal hWnd As IntPtr, ByVal Lparam As IntPtr) As Boolean
If IsWindowVisible(hWnd) Then
Dim TheLength As Integer = GetWindowTextLengthA(hWnd)
Dim TheReturn(TheLength * 2) As Byte
GetWindowText(hWnd, TheReturn, TheLength + 1)
Dim TheText As String = ""
For x = 0 To (TheLength - 1) * 2
If TheReturn(x) <> 0 Then
TheText &= Chr(TheReturn(x))
End If
Next
If Not TheText = "" Then
ListBox1.Items.Add(TheText & " (" & CStr(hWnd) & ")")
End If
End If
Return True
End Function
Private Declare Function EnumWindows Lib "User32.dll" (ByVal WNDENUMPROC As EnumWindowDelegate, ByVal lparam As IntPtr) As Boolean
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal Hwnd As IntPtr, ByVal Txt As Byte(), ByVal Lng As Integer) As Integer
Private Declare Function IsWindowVisible Lib "User32.dll" (ByVal hwnd As IntPtr) As Boolean
Private Declare Function GetWindowTextLengthA Lib "User32.dll" (ByVal hwnd As IntPtr) As Integer