为何以下两个程序输出结果不相同,求高手指教!
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPrivate Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
'上述代码匀为以下两个程序的共同引用部分
**********************************************************************
'程序代码1:
'本程序运行后要求输入Text1.Text值为vbNullString,Text2.Text值为API函数测试(注:这两个值都没有两边双引号)
Private Sub Command1_Click()
Dim Hw As Long, Cnt As Long, Cnt2 As Long, WinID As Long
Dim Rttitle As String * 256, Rttitle2 As String * 256
Dim Te1, Te2
Te1 = IIf(Text1.Text <> "vbNullString", Chr(34) & Trim(Text1.Text) & Chr(34),vbNullString)
Te2 = IIf(Text2.Text <> "vbNullString", Chr(34) & Trim(Text2.Text) & Chr(34),vbNullString)
WinID = FindWindow(Te1, Te2)
Do
Hw = FindWindowEx(WinID, Hw, vbNullString, vbNullString)
If Hw = 0 Then Exit Do
Cnt = GetWindowText(Hw, Rttitle, 255)
Cnt2 = GetClassName(Hw, Rttitle2, 255)
Text3.Text = Text3.Text & "控件ID:【" & Hw & "】控件类名:【" & Left(Rttitle2, Cnt2) & "】控件标题:【" & Left(Rttitle, Cnt) & "】" & vbCrLf
Loop
End Sub
'程序代码2
'本代码只是将程序代码1中要输入的部分省略了,改为直接设定!
Private Sub Command1_Click()
Dim Hw As Long, Cnt As Long, Cnt2 As Long, WinID As Long
Dim Rttitle As String * 256, Rttitle2 As String * 256
WinID = FindWindow(vbNullString, "API函数测试")
Do
Hw = FindWindowEx(WinID, Hw, vbNullString, vbNullString)
If Hw = 0 Then Exit Do
Cnt = GetWindowText(Hw, Rttitle, 255)
Cnt2 = GetClassName(Hw, Rttitle2, 255)
Text3.Text = Text3.Text & "控件ID:【" & Hw & "】控件类名:【" & Left(Rttitle2, Cnt2) & "】控件标题:【" & Left(Rttitle, Cnt) & "】" & vbCrLf
Loop
End Sub
*****************************************************************************************
上述两个代码在意义上只是相差一步,但运行结果就完全不相同,请高手指教指教!