求API EnumChildWindows函数在vfp中的用法!
当我们知道主窗口的句柄,需要对窗口下面的所有控件操作时,需要获得各控件的句柄
API函数 EnumChildWindows具有获得所有子窗口句柄的功能,下面是搜集的 EnumChildWindows相关信息,哪位
将其转换为vfp,先谢谢!!!
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定制控件。子窗口下属的子窗口也可由这个函数枚举
***************************
【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.)
********************************
在http://topic.csdn.net/t/20040907/17/3349285.html中
使用EnumChildWindows
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Sub Command1_Click()
Dim twnd As Long
twnd = FindWindow(vbNullString, "测试enabled")
EnumChildWindows twnd, AddressOf EnumChildProc, ByVal 0&
End Sub
模块
Option Explicit
Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Public Function EnumChildProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
Dim lpClassName As String
Dim retval As Long
Dim mname As String
Dim i As Integer
lpClassName = Space(256)
retval = GetClassName(hwnd, lpClassName, 256)
i = InStr(1, lpClassName, Chr(0))
mname = Left(lpClassName, i - 1)
Form1.List1.AddItem hwnd & " " & mname
EnumChildProc = 1
End Function
也可参考http://topic.csdn.net/t/20050314/14/3849303.html
http://dev.csdn.net/article/23/23336.shtm
[解决办法]
可以使用了:
Declare Long WinExec In kernel32 String,Long &&运行指定的程序Declare Long GetClassName In WIN32API Long HWnd,String @lpClassName,Long nMaxCount &&获得指定窗口所属的类的类名Declare Long GetWindowText In WIN32API Integer HWnd,String @lpText,Long nMaxCount &&函数将指定窗口的标题条文本(如果存在)拷贝到一个缓存区内。如果指定的窗口是一个控制,则拷贝控制的文本。Declare Long FindWindow In WIN32API String lpClassName,String lpWindowName &&函数返回与指定字符创相匹配的窗口类名或窗口名的最顶层窗口的窗口句柄。这个函数不会查找子窗口。Declare Long FindWindowEx In WIN32API Long hwndParent,Long hwndChildAfter,String @lpszClass,String @lpszWindow &&函数获得一个窗口的句柄,该窗口的类名和窗口名与给定的字符串相匹配。这个函数查找子窗口,从排在给定的子窗口后面的下一个子窗口开始。在查找时不区分大小写。Declare Long SendMessage In WIN32API Long HWnd,Long Msg,Long wParam,String @IParam &&函数将指定的消息发送到一个或多个窗口。此函数为指定的窗口调用窗口程序,直到窗口程序处理完消息再返回。而函数PostMessage不同,将一个消息寄送到一个线程的消息队列后立即返回。Declare Long PostMessage In WIN32API Long HWnd,Long Msg,Long wParam,String @IParam &&函数将一个消息放入(寄送)到与指定窗口创建的线程相联系消息队列里,不等待线程处理消息就返回,是异步消息模式。Declare Long GetWindowRect In WIN32API Integer HWnd,String @lpRect &&函数返回指定窗口的边框矩形的尺寸。该尺寸以相对于屏幕坐标左上角的屏幕坐标给出。Declare Long SetCursorPos In WIN32API Integer X,Integer Y &&函数把光标移到屏幕的指定位置。Declare mouse_event In Win32API Integer dwFlags,Integer dx,Integer dy,Integer cButtons,Integer dwExtraInfo &&函数综合鼠标击键和鼠标动作。#Define EM_REPLACESEL 0x00C2#Define MOUSEEVENTF_LEFTDOWN 0x0002#Define MOUSEEVENTF_LEFTUP 0x0004#Define BM_CLICK 0x00F5=WinExec("c:\自动对时器.exe",1) &&假设 自动对时器.exe 和 文件密码.dat 均在 C:\Create Cursor T1 (ObjectID I,ParentID I,ClassName C(50),ObjectText C(50))lcCaption="请输入密码" &&要查找窗口的标题lnHandle=FindWindow(Null,lcCaption)If lnHandle>0 lnChildHandle=0 lnChildHandle=FindWindowEx(lnHandle,lnChildHandle,Null,Null) Store Space(256) To lpClassName,lpText GetClassName(lnChildHandle,@lpClassName,256) GetWindowText(lnChildHandle,@lpText,256) If lnChildHandle<>0 lnHandle=lnChildHandle lnChildHandle=0 Do While .T. lnChildHandle=FindWindowEx(lnHandle,lnChildHandle,Null,Null) If lnChildHandle<>0 Store Space(256) To lpClassName,lpText GetClassName(lnChildHandle,@lpClassName,256) GetWindowText(lnChildHandle,@lpText,256) Insert Into T1 Values (lnChildHandle,lnHandle,Strtran(lpClassName,Chr(0),""),Strtran(lpText,Chr(0),"")) Loop Else Exit Endif Enddo Endif Select * Into Cursor T2 From T1 Where ClassName="TPanel" Select T2 Scan lnHandle=ObjectID lnChildHandle=0 Do While .T. lnChildHandle=FindWindowEx(lnHandle,lnChildHandle,Null,Null) If lnChildHandle<>0 Store Space(256) To lpClassName,lpText GetClassName(lnChildHandle,@lpClassName,256) GetWindowText(lnChildHandle,@lpText,256) Insert Into T1 Values (lnChildHandle,lnHandle,Strtran(lpClassName,Chr(0),""),Strtran(lpText,Chr(0),"")) Loop Else Exit Endif Enddo Endscan Select T1 Locate For Alltrim(ObjectText)=="使用文件做密码" If Found() lcRect=Replicate(Chr(0),16) If GetWindowRect(ObjectID,@lcRect)#0 lnLeftUpX=CToBin(Substr(lcRect,1,4),'4rs') &&左上角 X 坐标 lnLeftUpY=CToBin(Substr(lcRect,5,4),'4rs') &&左上角 Y 坐标 lnRightDownX=CToBin(Substr(lcRect,9,4),'4rs') &&右下角 X 坐标 lnRightDownY=CToBin(Substr(lcRect,13,4),'4rs') &&右下角 Y 坐标 SetCursorPos(lnLeftUpX+(lnRightDownX-lnLeftUpX)/2,lnLeftUpY+(lnRightDownY-lnLeftUpY)/2) &&鼠标移到 CHECKBOX =mouse_event(MOUSEEVENTF_LEFTDOWN+MOUSEEVENTF_LEFTUP,0,0,0,0) &&单击左键(按下再松开的组合) Wait '' Window At 10,10 Timeout 0.1 Endif lnParentID=ParentID Locate For ClassName="TEdit" And ParentID=lnParentID If Found() SendMessage(ObjectID,EM_REPLACESEL,0,"C:\文件密码.dat") &&假设 自动对时器.exe 和 文件密码.dat 均在 C:\ Endif Locate For ClassName="TEdit" And ParentID<>lnParentID If Found() SendMessage(ObjectID,EM_REPLACESEL,0,"123") &&密码 123 Endif Locate For Alltrim(ObjectText)=="确 定" If Found() PostMessage(ObjectID,BM_CLICK,0,'') Endif EndifElse Messagebox("没有找到 ["+lcCaption+"] 窗体!"+Space(5),48,"信息提示")EndifClear Dlls