| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1670 人关注过本帖
标题:为何以下两个程序输出结果不相同,求高手指教!
只看楼主 加入收藏
shi781203
Rank: 2
来 自:广东省
等 级:论坛游民
帖 子:112
专家分:50
注 册:2011-3-18
结帖率:37.14%
收藏
已结贴  问题点数:4 回复次数:2 
为何以下两个程序输出结果不相同,求高手指教!
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private 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
*****************************************************************************************
上述两个代码在意义上只是相差一步,但运行结果就完全不相同,请高手指教指教!
2016-05-12 23:13
hjxlj
Rank: 10Rank: 10Rank: 10
来 自:江西
等 级:贵宾
威 望:14
帖 子:292
专家分:1519
注 册:2013-6-25
收藏
得分:4 
运行结果是什么结果?

本人QQ:775420425
2016-05-14 15:25
shi781203
Rank: 2
来 自:广东省
等 级:论坛游民
帖 子:112
专家分:50
注 册:2011-3-18
收藏
得分:0 
回复 2楼 hjxlj
上面的代码可以将由桌面开始查找子窗口,结果查到很多子窗口,这并非本人想查的结果;
而下面的代码则查找到指定窗体内的所有子窗口,因此能找到本人所写窗体内的六个子窗口及按扭!

(如果上面代码的编辑框的值能够正确传递到API函数的参数,就会与下面的代码查找子窗口的结果一样)请高手指点指点吧,本人会多给你分的!

飞点燃费盐--历史上至有型的计算机病毒(能感染你是我的荣幸,也是你的光荣!)
2016-06-04 00:06
快速回复:为何以下两个程序输出结果不相同,求高手指教!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.073345 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved