请教API

luofenghen 2010-06-25 09:14:13

hProcess = OpenProcess(PROCESS_ALL_ACCESS, False, ProcessInfo.th32ProcessID)'得到进程的句柄 每一次运行的值都不一样的 有疑惑?

a = EnumChildWindows(hProcess, AddressOf EnumChildProc, 0) '得到相关窗体的控件的句柄
'EnumChildProc 这个函数不懂怎么写? 我自己写的就是返回1, a的值永远是0 ,还有如何循环? 用for?
...全文
113 21 打赏 收藏 转发到动态 举报
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
嗷嗷叫的老马 2010-06-25
  • 打赏
  • 举报
回复
对于WINDOWS系统来说....所有的那些窗体元素都是"窗口",无论按钮,窗体,还是图片框,都是"窗口".

所以这个系统就叫"Windows",加了复数的Window,哈哈.

所以EnumChildWindows枚举得到的"子窗口",并不是你所看到的"窗体",而是所有能枚举出来的子控件.
a1875566250 2010-06-25
  • 打赏
  • 举报
回复
OpenProcess返回后的进程值不一样就是这样的,因为句柄不会每次都是一样的。
LZ应该是像枚举一个进程所有的窗口,那不能使用EnumChildWindows,因为EnumChildWindows枚举的条件的一个父Hwnd而不是hprocess,只能使用EnumThreadWindows才能枚举一个进程的窗口。
而EnumThreadWindows也不能使用hprocess。
请使用Process32First+Process32Next枚举系统进程,然后使用Thread32First+Thread32Next枚举进程中的线程,然后EnumThreadWindows+EnumChildWindows一层一层向下枚举。
luofenghen 2010-06-25
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 myjian 的回复:]
这个.......知道为什么Windows叫"Windows"吗?
[/Quote]
不知道~ 麻烦老马解释一下~
嗷嗷叫的老马 2010-06-25
  • 打赏
  • 举报
回复
这个.......知道为什么Windows叫"Windows"吗?
luofenghen 2010-06-25
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 lyserver 的回复:]
使用EnumChildWindows枚举的是指定窗口的子窗口,如果该窗口没有子窗口,就不会调用回调函数了。
[/Quote]
这个是得到窗口的控件的句柄的 不是子窗口的
嗷嗷叫的老马 2010-06-25
  • 打赏
  • 举报
回复
关注一下.
lyserver 2010-06-25
  • 打赏
  • 举报
回复
使用EnumChildWindows枚举的是指定窗口的子窗口,如果该窗口没有子窗口,就不会调用回调函数了。
luofenghen 2010-06-25
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 lyserver 的回复:]
可以在EnumWindowsProc里设置断点或输出信息来判断是否执行了(当然,如果没有窗口,则不会调用该函数),EnumWindowsProc值设置为True表示继续枚举,否则中断枚举。
[/Quote]
有用 怎么判断是没有窗口呢 我找到了进程 得到了句柄 不就说明这个窗口是存在的吗?
lyserver 2010-06-25
  • 打赏
  • 举报
回复
可以在EnumWindowsProc里设置断点或输出信息来判断是否执行了(当然,如果没有窗口,则不会调用该函数),EnumWindowsProc值设置为True表示继续枚举,否则中断枚举。
luofenghen 2010-06-25
  • 打赏
  • 举报
回复
2楼说的很清楚了 谢谢了
那第2个问题呢 就是EnumChildWindows 返回值一直为0是为什么?
还有我怎么看 EnumWindowsProc这个函数执行了呢?
chinaboyzyq 2010-06-25
  • 打赏
  • 举报
回复
【VB声明】
Private Declare Function EnumChildWindows Lib "user32" Alias "EnumChildWindows" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long

【说明】
为指定的父窗口枚举子窗口

【返回值】
Long,非零表示成功,零表示失败

【备注】
在vb4下要求dwcbkd32.ocx定制控件。子窗口下属的子窗口也可由这个函数枚举

【参数表】
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.)

东方之珠 2010-06-25
  • 打赏
  • 举报
回复
'标准模块
Option Explicit

Private Declare Function GetClassName Lib "user32.dll" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
'Public Declare Function EnumChildWindows Lib "user32.dll" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Boolean
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 GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
'Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByRef lParam As Any) As Long
'Private Const WM_CLOSE As Long = &H10&

Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean
Dim WindowCaption As String, LengthCaption As Long, WindowClassName As String * 256
LengthCaption = GetWindowTextLength(hwnd)
WindowCaption = Space(LengthCaption)
Call GetWindowText(hwnd, WindowCaption, LengthCaption + 1)
Call GetClassName(hwnd, WindowClassName, 256)
WindowClassName = Left(WindowClassName, InStr(WindowClassName, Chr(0)) - 1)
Form1.List1.AddItem "窗口句柄:" & hwnd & " 窗口标题:" & WindowCaption & "窗口类名:" & WindowClassName
'If InStr(1, WindowCaption, "窗体的标题") > 0 Then
' SendMessage hwnd, WM_CLOSE, 0&, 0& '关闭指定窗体标题的窗体
'End If
EnumWindowsProc = True
End Function



'窗体Form1代码
Option Explicit
'窗体上添加一个命令按钮Command1,一个列表框List1
Private Sub Command1_Click()
EnumWindows AddressOf EnumWindowsProc, ByVal 0&
End Sub
东方之珠 2010-06-25
  • 打赏
  • 举报
回复
EnumChildProc代码必须写在标准模块中,编写成窗口处理程序(回调)。
luofenghen 2010-06-25
  • 打赏
  • 举报
回复
谢谢 chenjl1031

(东方之珠) 我先看看
东方之珠 2010-06-25
  • 打赏
  • 举报
回复
'标准模块
Option Explicit

Private Declare Function GetClassName Lib "user32.dll" Alias "GetClassNameA" (ByVal hWnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Public Declare Function EnumChildWindows Lib "user32.dll" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Boolean
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 GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hWnd As Long) As Long
'Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByRef lParam As Any) As Long
'Private Const WM_CLOSE As Long = &H10&


'枚举顶级窗口
Public Function EnumWindowsProc(ByVal hWnd As Long, ByVal lParam As Long) As Boolean
Dim WindowCaption As String, LengthCaption As Long, WindowClassName As String * 256
LengthCaption = GetWindowTextLength(hWnd)
WindowCaption = Space(LengthCaption)
Call GetWindowText(hWnd, WindowCaption, LengthCaption + 1)
Call GetClassName(hWnd, WindowClassName, 256)
WindowClassName = Left(WindowClassName, InStr(WindowClassName, Chr(0)) - 1)
Form1.List1.AddItem "窗口句柄:" & hWnd & " 窗口标题:" & WindowCaption & "窗口类名:" & WindowClassName
'If InStr(1, WindowCaption, "窗体的标题") > 0 Then
' SendMessage hwnd, WM_CLOSE, 0&, 0& '关闭指定窗体标题的窗体
'End If
EnumWindowsProc = True
End Function

'枚举所有子窗口
Public Function EnumChildWindowsProc(ByVal hWnd As Long, ByVal lParam As Long) As Boolean
Dim WindowCaption As String, LengthCaption As Long, WindowClassName As String * 256
LengthCaption = GetWindowTextLength(hWnd)
WindowCaption = Space(LengthCaption)
Call GetWindowText(hWnd, WindowCaption, LengthCaption + 1)
Call GetClassName(hWnd, WindowClassName, 256)

WindowClassName = Left(WindowClassName, InStr(WindowClassName, Chr(0)) - 1)
Form1.List2.AddItem "子窗口句柄:" & hWnd & " 子窗口标题:" & WindowCaption & " 子窗口类名:" & WindowClassName
'Debug.Print hWnd
'Form1.List2.AddItem hWnd & " " & WindowCaption
EnumChildWindowsProc = True
End Function


'窗体Form1代码
Option Explicit
'窗体上添加一个命令按钮Command1,二个列表框List1,List2
Private Sub Command1_Click()
EnumWindows AddressOf EnumWindowsProc, ByVal 0&
End Sub

Private Sub List1_Click()
Dim p1 As Long, p2 As Long
p1 = InStr(1, List1.List(List1.ListIndex), ":")
p2 = InStr(1, List1.List(List1.ListIndex), "窗口标题")
Debug.Print Mid$(List1.List(List1.ListIndex), p1 + 1, p2 - p1 - 1)
If p2 - p1 > 0 Then EnumChildWindows CLng(Mid$(List1.List(List1.ListIndex), p1 + 1, p2 - p1 - 1)), AddressOf EnumChildWindowsProc, ByVal 0&
End Sub
luofenghen 2010-06-25
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 lyserver 的回复:]
使用EnumChildWindows枚举的是指定窗口的子窗口,如果该窗口没有子窗口,就不会调用回调函数了。
[/Quote]
可以用什么得到控件吗?
luofenghen 2010-06-25
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 a1875566250 的回复:]
OpenProcess返回后的进程值不一样就是这样的,因为句柄不会每次都是一样的。
LZ应该是像枚举一个进程所有的窗口,那不能使用EnumChildWindows,因为EnumChildWindows枚举的条件的一个父Hwnd而不是hprocess,只能使用EnumThreadWindows才能枚举一个进程的窗口。
而EnumThreadWindows也不能使用hprocess。
请使用Pr……
[/Quote]
得不到 子窗体句柄 EnumThreadWindows返回的是1
hehaiyi2008 2010-06-25
  • 打赏
  • 举报
回复
学习!!!!!!!!!!
赵4老师 2010-06-25
  • 打赏
  • 举报
回复
《Windows核心编程》
《深入解析Windows操作系统-Windows Internals》
luofenghen 2010-06-25
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 myjian 的回复:]
对于WINDOWS系统来说....所有的那些窗体元素都是"窗口",无论按钮,窗体,还是图片框,都是"窗口".

所以这个系统就叫"Windows",加了复数的Window,哈哈.

所以EnumChildWindows枚举得到的"子窗口",并不是你所看到的"窗体",而是所有能枚举出来的子控件.
[/Quote]
哦~ 懂了 我太俗了
加载更多回复(1)
微信小程序系统教程[初级阶段],微信小程序0基础学起,讲解微信小程序开发的基础知识。 微信小程序系统教程共有“微信小程序系统教程[初级阶段]”、“微信小程序系统教程[中级阶段]——核心技术”、“微信小程序系统教程[阶段]客服消息+微信支付+九宝电商系统”。 “微信小程序系统教程[阶段]全套课程”包含: 1.微信小程序系统教程[阶段]_客服消息 2.微信小程序系统教程[阶段]_微信支付 3.微信小程序系统教程[阶段]_九宝电商系统 学习“微信小程序系统教程[阶段]”要求有微信小程序的基础。建议先学习“微信小程序系统教程[初级阶段]”、“微信小程序系统教程[中级阶段]”,后在报名“微信小程序系统教程[阶段]”。 阶段讲解的客服消息,是针对小程序的。后台程序用接近底层的技术,没有使用三方技术。这样降低同学们学习成本。 微信支付,这部分课程很有难度,要求同学们认真听讲,有不会的技术问题可以请教老师。购买课程后请联系老师,提供单号,给你源程序。 九宝电商系统是一套十分适和学习、项目的课程。既可以系统的学习微信小程序相关知识,还可以修改后上线。 “微信小程序系统教程[中级阶段]——核心技术”重点讲解微信小程序事件、组件、API 微信小程序系统教程[初级阶段],微信小程序0基础学起,讲解微信小程序开发的基础知识。 购买课程的同学,可赠送就九宝老师编写的《微信小程序开发宝典》。 购课请咨询qq2326321088

1,486

社区成员

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

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