下面是VB6的代码,因对VB6的语法不熟悉,各位麻烦帮个忙把下面的代码改为VB.NET?
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As LongPrivate Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Private Declare Function GetDlgItem Lib "user32" (ByVal hDlg As Long, ByVal nIDDlgItem As Long) As Long
Private Declare Function GetNextWindow Lib "user32" Alias "GetWindow" (ByVal hwnd As Long, ByVal wFlag As Long) As Long
Private Declare Sub Sleep Lib "kernel32.dll " (ByVal dwMilliseconds As Long)
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private DownName() As Long
Private DownHwnd() As Long
Public Function GetDown(ParentHwnd As Long) As String '这个ParentHwnd 参数就是窗体句柄
Dim temparr() As String
Dim hwnd As Long, L As Long
Dim tempstr1 As String * 256, tempstr2 As String * 256
Dim tempstr11 As String, tempstr22 As String
Dim ename As String
Dim i As Long
Dim a As String
ReDim temparr(3, 0)
hwnd = GetNextWindow(ParentHwnd, 5)
GetWindowText ParentHwnd, ename, 5
Dim js As Integer
Do
If hwnd > 0 Then
i = GetWindowTextLength(hwnd)
a = String$(i + 1, 0)
GetWindowText hwnd, a, Len(a)
hq = InStr(1, a, "共")
hq = hq + InStr(1, a, "正")
If hq > 0 Then
GetDown = getCaption(ParentHwnd) & " " & a
End If
End If
hwnd = GetNextWindow(hwnd, 2)
Loop While hwnd > 0
End Function
Public Function getCaption(hwnd As Long)
'获取窗口名称
Dim hWndlength As Long, hWndTitle As String, a As Long
hWndlength = GetWindowTextLength(hwnd)
hWndTitle = String$(hWndlength, 0)
a = GetWindowText(hwnd, hWndTitle, (hWndlength + 1))
b = Split(hWndTitle, "(")
getCaption = Left(b(1), Len(b(1)) - 1)
End Function
--------------------编程问答-------------------- 以下是我修改后的代码,但与原VB6执行的结果不相同,不知道出错在哪里。
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Integer, ByVal yPoint As Integer) As Integer
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Integer, ByVal lpString As String, ByVal cch As Integer) As Integer
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Integer) As Integer
Private Declare Function GetDlgItem Lib "user32" (ByVal hDlg As Integer, ByVal nIDDlgItem As Integer) As Integer
Private Declare Function GetNextWindow Lib "user32" Alias "GetWindow" (ByVal hwnd As Integer, ByVal wFlag As Integer) As Integer
Private Declare Sub Sleep Lib "kernel32.dll " (ByVal dwMilliseconds As Integer)
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Integer, ByVal lpClassName As String, ByVal nMaxCount As Integer) As Integer
Private DownName() As Integer
Private DownHwnd() As Integer
'获取程序的信息
Public Function GetDown(ByVal ParentHwnd As Integer) As String '这个ParentHwnd 参数就是窗体句柄
Dim temparr() As String
Dim hwnd As Integer, L As Integer
Dim tempstr1 As String
Dim tempstr2 As String
Dim tempstr11 As String
Dim tempstr22 As String
Dim ename As String
Dim i As Integer
'Dim a As String
ReDim Preserve temparr(3)
hwnd = GetNextWindow(ParentHwnd, 5)
GetWindowText(ParentHwnd, ename, 5)
Dim js As Integer
Do
If hwnd > 0 Then
i = GetWindowTextLength(hwnd)
Dim a As New String(CChar(CStr(i + 1)), 0)
GetWindowText(hwnd, a, Len(a))
Dim hq As String
hq = InStr(1, a, "共")
hq = hq + InStr(1, a, "正")
If hq > 0 Then
GetDown = getCaption(ParentHwnd) & " " & a
End If
End If
hwnd = GetNextWindow(hwnd, 2)
Loop While hwnd > 0
End Function
Public Function getCaption(ByVal hwnd As Integer)
'获取窗口名称
Dim hWndlength As Integer, a As Integer
hWndlength = GetWindowTextLength(hwnd)
Dim hWndTitle As New String(CChar(CStr(hWndlength)), 0)
a = GetWindowText(hwnd, hWndTitle, (hWndlength + 1))
Dim b As String() = Split(hWndTitle, "(")
getCaption = Left(b(1), Len(b(1)) - 1)
End Function
--------------------编程问答-------------------- 在vb.net我把这段修改的代码保存为类文件 Class1 ,在其它窗体引用
Dim objdb As New Class1
Dim hWnd As Integer= 172818 '窗体句柄
Dim str2 As String = objdb.GetDown(hWnd)
vb6 中代码返回则是一段字符串 "共200392mb,速度98kb/s";
vb.net 通过我自己修后的代码,则返回是Nothing, 应当是我修改后代码不正确,望各位能够帮我看看。 --------------------编程问答-------------------- vb.net有导入VB6代码的功能的
补充:VB , API