下面是VB6的代码,因对VB6的语法不熟悉,各位麻烦帮个忙把下面的代码改为VB.NET?

[复制链接]
查看11 | 回复5 | 2021-1-27 06:31:08 | 显示全部楼层 |阅读模式
PrivateDeclareFunctionWindowFromPointLib"user32"(ByValxPointAsLong,ByValyPointAsLong)AsLong
PrivateDeclareFunctionGetWindowTextLib"user32"Alias"GetWindowTextA"(ByValhwndAsLong,ByVallpStringAsString,ByValcchAsLong)AsLong
PrivateDeclareFunctionFindWindowLib"user32"Alias"FindWindowA"(ByVallpClassNameAsString,ByVallpWindowNameAsString)AsLong
PrivateDeclareFunctionGetWindowTextLengthLib"user32"Alias"GetWindowTextLengthA"(ByValhwndAsLong)AsLong
PrivateDeclareFunctionGetDlgItemLib"user32"(ByValhDlgAsLong,ByValnIDDlgItemAsLong)AsLong
PrivateDeclareFunctionGetNextWindowLib"user32"Alias"GetWindow"(ByValhwndAsLong,ByValwFlagAsLong)AsLong
PrivateDeclareSubSleepLib"kernel32.dll"(ByValdwMillisecondsAsLong)
PrivateDeclareFunctionGetClassNameLib"user32"Alias"GetClassNameA"(ByValhwndAsLong,ByVallpClassNameAsString,ByValnMaxCountAsLong)AsLong
PrivateDownName()AsLong
PrivateDownHwnd()AsLong
PublicFunctionGetDown(ParentHwndAsLong)AsString'这个ParentHwnd参数就是窗体句柄
Dimtemparr()AsString
DimhwndAsLong,LAsLong
Dimtempstr1AsString*256,tempstr2AsString*256
Dimtempstr11AsString,tempstr22AsString
DimenameAsString
DimiAsLong
DimaAsString
ReDimtemparr(3,0)
hwnd=GetNextWindow(ParentHwnd,5)
GetWindowTextParentHwnd,ename,5
DimjsAsInteger
Do
Ifhwnd>0Then
i=GetWindowTextLength(hwnd)
a=String$(i+1,0)
GetWindowTexthwnd,a,Len(a)
hq=InStr(1,a,"共")
hq=hq+InStr(1,a,"正")
Ifhq>0Then
GetDown=getCaption(ParentHwnd)&""&a
EndIf
EndIf
hwnd=GetNextWindow(hwnd,2)
LoopWhilehwnd>0
EndFunction
PublicFunctiongetCaption(hwndAsLong)
'获取窗口名称
DimhWndlengthAsLong,hWndTitleAsString,aAsLong
hWndlength=GetWindowTextLength(hwnd)
hWndTitle=String$(hWndlength,0)
a=GetWindowText(hwnd,hWndTitle,(hWndlength+1))
b=Split(hWndTitle,"(")
getCaption=Left(b(1),Len(b(1))-1)
EndFunction
分 -->
回复

使用道具 举报

千问 | 2021-1-27 06:31:08 | 显示全部楼层
以下是我修改后的代码,但与原VB6执行的结果不相同,不知道出错在哪里。
PrivateDeclareFunctionWindowFromPointLib"user32"(ByValxPointAsInteger,ByValyPointAsInteger)AsInteger
PrivateDeclareFunctionGetWindowTextLib"user32"Alias"GetWindowTextA"(ByValhwndAsInteger,ByVallpStringAsString,ByValcchAsInteger)AsInteger
PrivateDeclareFunctionFindWindowLib"user32"Alias"FindWindowA"(ByVallpClassNameAsString,ByVallpWindowNameAsString)AsInteger
PrivateDeclareFunctionGetWindowTextLengthLib"user32"Alias"GetWindowTextLengthA"(ByValhwndAsInteger)AsInteger
PrivateDeclareFunctionGetDlgItemLib"user32"(ByValhDlgAsInteger,ByValnIDDlgItemAsInteger)AsInteger
PrivateDeclareFunctionGetNextWindowLib"user32"Alias"GetWindow"(ByValhwndAsInteger,ByValwFlagAsInteger)AsInteger
PrivateDeclareSubSleepLib"kernel32.dll"(ByValdwMillisecondsAsInteger)
PrivateDeclareFunctionGetClassNameLib"user32"Alias"GetClassNameA"(ByValhwndAsInteger,ByVallpClassNameAsString,ByValnMaxCountAsInteger)AsInteger
PrivateDownName()AsInteger
PrivateDownHwnd()AsInteger
'获取程序的信息
PublicFunctionGetDown(ByValParentHwndAsInteger)AsString'这个ParentHwnd参数就是窗体句柄
Dimtemparr()AsString
DimhwndAsInteger,LAsInteger
Dimtempstr1AsString
Dimtempstr2AsString
Dimtempstr11AsString
Dimtempstr22AsString
DimenameAsString
DimiAsInteger
'DimaAsString
ReDimPreservetemparr(3)
hwnd=GetNextWindow(ParentHwnd,5)
GetWindowText(ParentHwnd,ename,5)
DimjsAsInteger
Do
Ifhwnd>0Then
i=GetWindowTextLength(hwnd)
DimaAsNewString(CChar(CStr(i+1)),0)
GetWindowText(hwnd,a,Len(a))
DimhqAsString
hq=InStr(1,a,"共")
hq=hq+InStr(1,a,"正")
Ifhq>0Then
GetDown=getCaption(ParentHwnd)&""&a
EndIf
EndIf
hwnd=GetNextWindow(hwnd,2)
LoopWhilehwnd>0
EndFunction
PublicFunctiongetCaption(ByValhwndAsInteger)
'获取窗口名称
DimhWndlengthAsInteger,aAsInteger
hWndlength=GetWindowTextLength(hwnd)
DimhWndTitleAsNewString(CChar(CStr(hWndlength)),0)
a=GetWindowText(hwnd,hWndTitle,(hWndlength+1))
DimbAsString()=Split(hWndTitle,"(")
getCaption=Left(b(1),Len(b(1))-1)
EndFunction

回复

使用道具 举报

千问 | 2021-1-27 06:31:08 | 显示全部楼层
这个涉及到另一个程序的问题,别人不方便帮你调试,建议你单步调试,看看哪一步不对,把那个步骤的调用、上下文参数、不同在哪里等等贴出来,看看能不能帮到你。
回复

使用道具 举报

千问 | 2021-1-27 06:31:08 | 显示全部楼层
在vb.net我把这段修改的代码保存为类文件Class1,在其它窗体只引用
DimobjdbAsNewClass1
DimhWndAsInteger=172818'窗体句柄
Dimstr2AsString=objdb.GetDown(hWnd)

回复

使用道具 举报

千问 | 2021-1-27 06:31:08 | 显示全部楼层
vb6中代码返回则是一段字符串"共200392mb,速度98kb/s";
vb.net通过我自己修后的代码,则返回是Nothing,应当是我修改后代码不正确,望各位能够帮我看看。
回复

使用道具 举报

千问 | 2021-1-27 06:31:08 | 显示全部楼层
你还是可以按F11一步步调试的啊!看看那步开始出错了
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行