如何使用FindWindowEx遍历各文本框?

davidnb 2004-08-20 11:17:51
我能使用FindWindowEx取得外部程序窗口中的某个文本框的值,但该窗口中有很多个文本框,问题是:

1。 我如何逐个访问各文本框取值?
2。 我如何指定访问某个文本框的值?

研究了半天不得其解,请教高手啊:)

Thanks for any suggestion!
...全文
2080 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
davidnb 2004-08-26
  • 打赏
  • 举报
回复
挖靠几天没来就有了这么多回复,前些年总感叹老外热情,没想到现在大家也很热心啊。

逐个访问各文本框取值各位已经说了。
访问某个文本框的值估计是要事先认定该文本框是第几个子窗口吧,如其位置是固定的,那这问题也解决了。

似乎可以结了,顺便问一下pb做的窗口里有些类名是pdw估计从中取值是没戏了吧?

thanks for everyone again!
rainstormmaster 2004-08-21
  • 打赏
  • 举报
回复
用循环就可以了,先来看一下findwindowex的说明:
【VB声明】
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

【别名】
FindWindowExA

【说明】
在窗口列表中寻找与指定条件相符的第一个子窗口

【返回值】
Long,找到的窗口的句柄。如未找到相符窗口,则返回零。会设置GetLastError

【参数表】
hWnd1 ---------- Long,在其中查找子的父窗口。如设为零,表示使用桌面窗口(通常说的顶级窗口都被认为是桌面的子窗口,所以也会对它们进行查找)

hWnd2 ---------- Long,从这个窗口后开始查找。这样便可利用对FindWindowEx的多次调用找到符合条件的所有子窗口。如设为零,表示从第一个子窗口开始搜索
lpsz1 ---------- String,欲搜索的类名。零表示忽略
lpsz2 ---------- String,欲搜索的窗口的标题。零表示忽略

所以,你只要这样就可以了:
dim subhwnd as long
subhwnd=finwindowex(mhwnd,0,"窗口类名",vbnullstring)
do while subhwnd>0
subhwnd=finwindowex(mhwnd,subhwnd,"窗口类名",vbnullstring)
loop

goodname008 2004-08-20
  • 打赏
  • 举报
回复
EnumChildWindows

VB声明
Declare Function EnumChildWindows Lib "user32" Alias "EnumChildWindows" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
说明
为指定的父窗口枚举子窗口
返回值
Long,非零表示成功,零表示失败
参数表
参数 类型及说明
hWndParent Long,欲枚举子窗口的父窗口的句柄
lpEnumFunc Long,为每个子窗口调用的函数的指针。用AddressOf运算符获得函数在一个标准模块中的地址
lParam Long,在枚举期间,传递给dwcbkd32.ocx定制控件之EnumWindows事件的值。这个值的含义是由程序员规定的。(原文:Value that is passed to the EnumWindows event of the dwcbkd32.ocx custom control during enumeration. The meaning of this value is defined by the programmer.)
注解
在vb4下要求dwcbkd32.ocx定制控件。子窗口下属的子窗口也可由这个函数枚举

dongge2000 2004-08-20
  • 打赏
  • 举报
回复
Public Function WndEnumChildProc(ByVal hwnd As Long, ByVal lParam As ListView) As Long
Dim bRet As Long
Dim myStr As String * 50

bRet = GetClassName(hwnd, myStr, 50)
'if you want the text for only Edit class then use the if statement:
'If (Left(myStr, 4) = "Edit") Then
'lParam.Sorted = False

With lParam.ListItems
.Add.Text = Str(hwnd)
.Item(ICount).SubItems(1) = myStr
.Item(ICount).SubItems(2) = GetText(hwnd)
If SendMessage(hwnd, EM_GETPASSWORDCHAR, 0, 0) = 0 Then
.Item(ICount).SubItems(3) = "No"
Else
.Item(ICount).SubItems(3) = "Yes"
End If
End With

ICount = ICount + 1

'lParam.Sorted = True
'End If
WndEnumChildProc = 1

End Function

Function GetText(iHwnd As Long) As String
Dim Textlen As Long
Dim Text As String

Textlen = SendMessage(iHwnd, WM_GETTEXTLENGTH, 0, 0)
If Textlen = 0 Then
GetText = ">No text for this class<"
Exit Function
End If
Textlen = Textlen + 1
Text = Space(Textlen)
Textlen = SendMessage(iHwnd, WM_GETTEXT, Textlen, ByVal Text)
'The 'ByVal' keyword is necessary or you'll get an invalid page fault
'and the app crashes, and takes VB with it.
GetText = Left(Text, Textlen)

End Function
Public Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long

Public Function Cname(ByVal ChWnd As Long) As String
Cname = Space(85)
GetClassName ChWnd, Cname, Len(Cname)
End Function
====================
用到的API自己加吧!
walkonthesky 2004-08-20
  • 打赏
  • 举报
回复
遍历所有控件不就可以了吗
LGYAN 2004-08-20
  • 打赏
  • 举报
回复
楼主需要代码吗?
tztz520 2004-08-20
  • 打赏
  • 举报
回复
用getclassname可以得到类名
DragonFly_1976 2004-08-20
  • 打赏
  • 举报
回复
用findwindowex得到窗体句柄后,调用getwindow查找.
davidnb 2004-08-20
  • 打赏
  • 举报
回复
to loverpyh(龙行天下): 是外部程序

to tztz520(午夜逛街) : thanks, 我查查
tztz520 2004-08-20
  • 打赏
  • 举报
回复
楼主可以用GetNextWindow这个API获得一个窗体内所有控件类名.
再判断如果类名包含有"edit"这个字符串的话就是了
loverpyh 2004-08-20
  • 打赏
  • 举报
回复
dim cControl as Control
for each cControl in forms
if typeof cControl is Text then
do your job
end if
next

1,485

社区成员

发帖
与我相关
我的任务
社区描述
VB API
社区管理员
  • API
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧