求API EnumChildWindows函数在vfp中的用法!

lt5225262 2010-02-05 10:10:19
当我们知道主窗口的句柄,需要对窗口下面的所有控件操作时,需要获得各控件的句柄

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

...全文
544 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
十豆三 2010-02-08
  • 打赏
  • 举报
回复
可以使用了:


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
Endif
Else
Messagebox("没有找到 ["+lcCaption+"] 窗体!"+Space(5),48,"信息提示")
Endif
Clear Dlls
lt5225262 2010-02-08
  • 打赏
  • 举报
回复
谢谢 apple_8180大哥,程序写得精妙绝伦,完全解决问题了。祝你新年快乐!万事如意!
lt5225262 2010-02-07
  • 打赏
  • 举报
回复
9楼的代码基本解决问题了,如果再加上:点击“使用文件做密码”和点击“确 定”就更好了。
十豆三 2010-02-06
  • 打赏
  • 举报
回复
你上传到下载不了,最好压缩成.RAR后上传至:
http://www.access911.net/CSDN/
十豆三 2010-02-06
  • 打赏
  • 举报
回复
请参考:<WIN API-VFP获得其他程序多个输入框的内容>
http://blog.csdn.net/apple_8180/archive/2009/04/07/4054601.aspx
lt5225262 2010-02-06
  • 打赏
  • 举报
回复
例如运行一个加密的文件(“自动对时器.exe” 下载地址:http://xz.qupan.com/down/418911_5802468.html)
①运行时要输入密码:123 ;
②点击“使用文件做密码”;
③并选择“文件密码.dat”文件(下载地址: http://xz.qupan.com/down/418911_5802486.html 下载后改名为"文件密码.dat");
④点击确定。
希望上述动作用vfp程序来完成。我用手动操作spylite24程序能获得输入密码123中的句柄,
但用下面的代码未能得到输入密码123中的句柄,也就是说:下面的代码还不能取到所有控件的句柄。
*枚举窗体句柄
*-----------
Declare Integer LoadLibrary In WIN32API String
Declare Integer FreeLibrary In WIN32API Integer
Declare Integer GetProcAddress In WIN32API Integer hModule, String procname
Declare Integer GetProcessHeap In WIN32API
Declare Integer HeapAlloc In WIN32API Integer hHeap, Integer dwFlags, Integer dwBytes
Declare Integer HeapFree In WIN32API Integer hHeap&&, integer dwFlags, integer lpMem
Declare Integer GetWindowText In WIN32API Integer, String @, Integer
Declare Integer GetWindowLong In WIN32API Integer, Integer
Declare Integer EnumChildWindows In WIN32API Integer HWnd, Integer lpEnumProc, Integer Lparam
*制作:行者孙(QQ 310727570) VFP应用程式算法群(12787940)
Local cCmd,hProcHeap,cCmdnAddr,hModule,nAddr
Create Cursor WindHwnds (HWnd i)
cCmd=Strconv("INSERT INTO WindHwnds (hWnd) VALUES (%d)"+0h00,5)
hProcHeap = GetProcessHeap()
cCmdnAddr = HeapAlloc(hProcHeap, 0,Len(cCmd))
Sys(2600,cCmdnAddr,Len(cCmd),cCmd)
hModule=LoadLibrary("msvcrt")
nAddr=GetProcAddress(hModule,"swprintf")
CallDllCode1=0hB8+BinToC(nAddr,"4rs")+0hFFD0
FreeLibrary(hModule)
hModule=LoadLibrary("oleaut32")
nAddr=GetProcAddress(hModule,"SysAllocString" )
CallDllCode2=0hB8+BinToC(nAddr,"4rs")+0hFFD0
nAddr=GetProcAddress(hModule,"SysFreeString")
CallDllCode3=0hB8+BinToC(nAddr,"4rs")+0hFFD0
FreeLibrary(hModule)
sCode=0h558BEC81ECD00700008B450850B8+BinToC(cCmdnAddr,"4rs")
sCode=sCode+0h508D45A050+CallDllCode1
sCode=sCode+0h83C40C8D45A050 +CallDllCode2
sCode=sCode+0h8945F050B8+BinToC(Sys(3095,_vfp),"4rs")
sCode=sCode+0h508B000584000000FF1083F800+CallDllCode3
sCode=sCode+0hB8010000008BE55DC20800
AdrCode=HeapAlloc(hProcHeap,0,Len(sCode))
Sys(2600,AdrCode,Len(sCode),sCode)
EnumChildWindows(0,AdrCode,0)
HeapFree(hProcHeap)
INDEX on hwnd TAG hwnd
Browse &&显示枚举到的窗体句柄结果

请大家看看有什么好方法?
lt5225262 2010-02-06
  • 打赏
  • 举报
回复
感谢apple_8180兄提供这么多,我得好好消化消化。
十豆三 2010-02-06
  • 打赏
  • 举报
回复
*-- 转自红雨大侠
GetAllWinHander("TMP1") &&TMP1临时表名
Locate
Browse
* -------------------------------------
* 枚举所有当前进程窗口句柄、标题、类名、进程ID
* -------------------------------------
Function GetAllWinHander ( tcWindTable )
tcWindTable = IIF(para()=1 AND TYPE([tcWindTable])=[C], tcWindTable, [AllWindlists] )
#Define GW_HWNDNEXT 2
Declare integer FindWindow in "user32" string lpclassName, string lpWindowName
Declare integer GetWindow in "user32" integer hwnd, integer wFlag
Crea curs (tcWindTable) ( PnWinHand N(12), PcWinTitle C(254), PcWinClass C(254), PnWinProcID N(18))
Local lnHCurrent, lnWinCount, lcWinTitle
lnHCurrent = FindWindow( [Shell_TrayWnd], 0)
lnWinCount = 1 && 计数
Do WHILE lnHCurrent > 0
lcWinTitle = GetWinText( lnHCurrent )
lcWinClass = GetWinClass( lnHCurrent )
lnWinProcID = GetProcessIdFromHand( lnHCurrent )
Insert INTO (tcWindTable) (PnWinHand, PcWinTitle, PcWinClass, PnWinProcID ) ;
VALUES (lnHCurrent, lcWinTitle, lcWinClass, lnWinProcID )
lnWinCount = lnWinCount + 1
lnHCurrent = GetWindow( lnHCurrent, GW_HWNDNEXT ) && 得到下一个窗口句柄
Enddo
Endfunc
* -------------------------------------
* 由窗口句柄返回其类名
* -------------------------------------
Function GetWinClass ( lpnWinHand )
Local lcWinClass
lcWinClass = []
If TYPE([lpnWinHand])=[N]
Declare Integer GetClassName In user32 Integer, String @, Integer
lcWinClass = Repl( CHR( 0), 256)
lnClassLen = GetClassName( lpnWinHand, @lcWinClass, 255)
lcWinClass = Left( lcWinClass, lnClassLen)
Endif
Return lcWinClass
Endfunc
* -------------------------------------
* 由窗口句柄返回其标题
* -------------------------------------
Function GetWinText ( lpnWinHand )
Local lcWinText
lcWinText = []
If TYPE([lpnWinHand])=[N]
Declare Integer GetWindowText In user32 Integer, String @, Integer
lcWinText = Repl( CHR( 0), 256)
lnTextLen = GetWindowText( lpnWinHand, @lcWinText, 255)
lcWinText = Left( lcWinText, lnTextLen)
Endif
Return lcWinText
Endfunc
* -------------------------------------
* 由窗口句柄返回其进程Id
* -------------------------------------
Function GetProcessIdFromHand ( lpnWinHand )
Local lnProcessId
lnProcessId = 0
If TYPE([lpnWinHand])=[N]
Declare integer GetWindowThreadProcessId in "user32" integer hwnd, integer @lpdwProcessId
= GetWindowThreadProcessId( lpnWinHand, @lnProcessId )
Endif
Return lnProcessId
Endfunc
* -------------------------------------
* 枚举当前所有进程
* -------------------------------------
Function GetAllProcessID ( lpProcTable )
lpProcTable = IIF(para()=1 AND TYPE([lpProcTable])=[C], lpProcTable, [AllProclists] )
Declare integer CreateToolhelp32Snapshot in kernel32 integer lFlags, integer lProcessID
Declare integer Process32First in kernel32 integer hSnapShot, string @PROCESSENTRY32_uProcess
Declare integer Process32Next in kernel32 integer hSnapShot, string @PROCESSENTRY32_uProcess
Declare integer CloseHandle in kernel32 integer hObject
Declare integer GetLastError in kernel32
Crea curs (lpProcTable) (PdwSize N(3), PcntUsage N(12), ;
Pth32ProcessID N(12), Pth32DefaultHeapID N(12), ;
Pth32ModuleID N(12), PcntThreads N(12), ;
Pth32ParentProcessID N(12), PpcPriClassBase N(3), ;
PdwFlags N(3), PszExeFile C(254) )
lnHand = 0
lnHand = CreateToolhelp32Snapshot(3,0)
If lnHand>0
dwSize = Num2Dword(296)
cntUsage = Num2Dword(0)
th32ProcessID = Num2Dword(0)
th32DefaultHeapID = Num2Dword(0)
th32ModuleID = Num2Dword(0)
cntThreads = Num2Dword(0)
th32ParentProcessID = Num2Dword(0)
pcPriClassBase = Num2Dword(0)
dwFlags = Num2Dword(0)
szExeFile = Repli(CHR(0), 260)
lcTitle = dwSize + cntUsage + th32ProcessID + th32DefaultHeapID ;
+ th32ModuleID + cntThreads + th32ParentProcessID ;
+ pcPriClassBase + dwFlags + szExeFile
If Process32First(lnHand,@lcTitle) > 0 && 第一个进程是 kernel32.dll,没必要列出
Do while Process32Next(lnHand,@lcTitle)> 0
Insert INTO (lpProcTable) (PdwSize, PcntUsage, Pth32ProcessID, Pth32DefaultHeapID, ;
Pth32ModuleID, PcntThreads, Pth32ParentProcessID, ;
PpcPriClassBase, PdwFlags, PszExeFile) ;
VALUES ( ;
Dword2Num(Subs(lcTitle, 1,4)), ;
Dword2Num(Subs(lcTitle, 5,4)), ;
Dword2Num(Subs(lcTitle, 9,4)), ;
Dword2Num(Subs(lcTitle,13,4)), ;
Dword2Num(Subs(lcTitle,17,4)), ;
Dword2Num(Subs(lcTitle,21,4)), ;
Dword2Num(Subs(lcTitle,25,4)), ;
Dword2Num(Subs(lcTitle,29,4)), ;
Dword2Num(Subs(lcTitle,33,4)), ;
SUBSTR(SUBSTR(lcTitle, 37), 1, AT(CHR(0),SUBSTR(lcTitle, 37))-1) )
Enddo
Endif
= CloseHandle(lnHand)
Return .T.
Else
Return .F.
Endif
Endfunc
Function Num2Dword ( lpnNum )
Declare integer RtlMoveMemory in kernel32 as RtlCopyDword string @pDeststring, integer @pVoidSource, integer nLength
lcDword = SPACE(4)
= RtlCopyDword(@lcDword, bitor(lpnNum,0), 4)
Return lcDword
Endfunc
Function Dword2Num ( tcDword )
Declare integer RtlMoveMemory in kernel32 as RtlCopyNum integer @DestNumeric, string @pVoidSource, integer nLength
lnNum = 0
=RtlCopyNum(@lnNum, tcDword, 8)
Return lnNum
Endfunc
* -------------------------------------
* 从 ProcessId 关闭进程
* -------------------------------------
Function ExitProcessId ( lpnProcessId )
Declare integer TerminateProcess in kernel32 integer hProcess , integer uExitCode
Declare integer OpenProcess in kernel32 integer dwDesiredAccess, integer binheritHandle, integer dwProcessId
Declare integer GetCurrentProcessId in kernel32
If lpnProcessId = GetCurrentProcessId()
Return .F.
Else
hproc = OpenProcess(2035711, 0, lpnProcessId) && 从进程 ID 获得进程句柄
If hproc = 0
Return .F.
Else
= TerminateProcess(hproc, 0) && 关闭进程
Return .T.
Endif
Endif
Endfunc
* -------------------------------------
* 从 窗口句柄 关闭程序
* -------------------------------------
Function ExitWinHander ( lpnWinHand )
If TYPE([lpnWinHand])=[N]
If lpnWinHand # 0
Declare integer ShowWindowAsync in "user32" integer hwnd, integer nCmdShow
Declare integer SetForegroundWindow in "user32" integer hwnd
Declare integer SendMessage in win32api integer hwnd, integer wMsg, integer wParam, integer lParam
= ShowWindowAsync( lpnWinHand, 1 ) && 将窗口设为可见
= SetForegroundWindow( lpnWinHand ) && 将窗口设为系统的前台窗口
= SendMessage( lpnWinHand, 16, 0, 0 ) && 将退出消息发给那个窗口
Endif
Endif
Endfunc
* -------------------------------------
十豆三 2010-02-06
  • 打赏
  • 举报
回复
枚举窗体句柄
*-----------
Declare Integer LoadLibrary In WIN32API String
Declare Integer FreeLibrary In WIN32API Integer
Declare Integer GetProcAddress In WIN32API Integer hModule, String procname
Declare Integer GetProcessHeap In WIN32API
Declare Integer HeapAlloc In WIN32API Integer hHeap, Integer dwFlags, Integer dwBytes
Declare Integer HeapFree In WIN32API Integer hHeap&&, integer dwFlags, integer lpMem
Declare Integer GetWindowText In WIN32API Integer, String @, Integer
Declare Integer GetWindowLong In WIN32API Integer, Integer
Declare Integer EnumChildWindows In WIN32API Integer HWnd, Integer lpEnumProc, Integer Lparam
*制作:行者孙(QQ 310727570) VFP应用程式算法群(12787940)
Local cCmd,hProcHeap,cCmdnAddr,hModule,nAddr
Create Cursor WindHwnds (HWnd i)
cCmd=Strconv("INSERT INTO WindHwnds (hWnd) VALUES (%d)"+0h00,5)
hProcHeap = GetProcessHeap()
cCmdnAddr = HeapAlloc(hProcHeap, 0,Len(cCmd))
Sys(2600,cCmdnAddr,Len(cCmd),cCmd)
hModule=LoadLibrary("msvcrt")
nAddr=GetProcAddress(hModule,"swprintf")
CallDllCode1=0hB8+BinToC(nAddr,"4rs")+0hFFD0
FreeLibrary(hModule)
hModule=LoadLibrary("oleaut32")
nAddr=GetProcAddress(hModule,"SysAllocString" )
CallDllCode2=0hB8+BinToC(nAddr,"4rs")+0hFFD0
nAddr=GetProcAddress(hModule,"SysFreeString")
CallDllCode3=0hB8+BinToC(nAddr,"4rs")+0hFFD0
FreeLibrary(hModule)
sCode=0h558BEC81ECD00700008B450850B8+BinToC(cCmdnAddr,"4rs")
sCode=sCode+0h508D45A050+CallDllCode1
sCode=sCode+0h83C40C8D45A050 +CallDllCode2
sCode=sCode+0h8945F050B8+BinToC(Sys(3095,_vfp),"4rs")
sCode=sCode+0h508B000584000000FF1083F800+CallDllCode3
sCode=sCode+0hB8010000008BE55DC20800
AdrCode=HeapAlloc(hProcHeap,0,Len(sCode))
Sys(2600,AdrCode,Len(sCode),sCode)
EnumChildWindows(0,AdrCode,0)
HeapFree(hProcHeap)
Browse &&显示枚举到的窗体句柄结果
lt5225262 2010-02-06
  • 打赏
  • 举报
回复
谢谢apple_8180兄,你太热情了,非常感动!我先看看你的代码。
十豆三 2010-02-06
  • 打赏
  • 举报
回复
9楼代码还差一点,你可以先看看,下周我在抽时间完善一下。
十豆三 2010-02-06
  • 打赏
  • 举报
回复
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 lParam
Declare Long EnableWindow In WIN32API Long HWnd,Long fEnable
#Define EM_REPLACESEL 0xC
#Define BM_SETCHECK 0x00F1
#Define BM_CLICK 0xF5
#Define WM_COMMAND 0x0111

=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()
lnParentID=ParentID
Locate For ClassName="TEdit" And ParentID<>lnParentID
If Found()
SendMessage(ObjectID,EM_REPLACESEL,0,"123") &&密码 123
Endif
Locate For ClassName="TEdit" And ParentID=lnParentID
If Found()
SendMessage(ObjectID,EM_REPLACESEL,0,"C:\文件密码.dat") &&假设 自动对时器.exe 和 文件密码.dat 均在 C:\
Endif
Locate For Alltrim(ObjectText)=="确 定"
If Found()
EnableWindow(ObjectID,1)
*SendMessage(ObjectID,BM_CLICK,0,'')
Endif
Endif
Else
Messagebox("没有找到 ["+lcCaption+"] 窗体!"+Space(5),48,"信息提示")
Endif
lt5225262 2010-02-06
  • 打赏
  • 举报
回复
请参考: <WIN API-VFP获得其他程序多个输入框的内容>
http://blog.csdn.net/apple_8180/archive/2009/04/07/4054601.aspx

由于该输入密码的TEdit的句柄属于第四级,从主窗口开始类名分别为:
TForm8->TPanel->TPanel
|
->TPanel->TEdit
所以也取不到TEdit的句柄。并且在第第二级的TPanel下级,有两个同级的TPanel,都没有标题,这两个TPanel的控件ID每次重新打开窗口后都会变化。
lt5225262 2010-02-06
  • 打赏
  • 举报
回复
已经上传至http://www.access911.net/CSDN/FileDescription.asp?id=6&mdb=2010-2-6&mode=1
API之网络函数1. API之网络函数 WNetAddConnection 创建同一个网络资源的永久性连接 WNetAddConnection2 创建同一个网络资源的连接 WNetAddConnection3 创建同一个网络资源的连接 WNetCancelConnection 结束一个网络连接 WNetCancelConnection2 结束一个网络连接 WNetCloseEnum 结束一次枚举操作 WNetConnectionDialog 启动一个标准对话框,以便建立同网络资源的连接 WNetDisconnectDialog 启动一个标准对话框,以便断开同网络资源的连接 WNetEnumResource 枚举网络资源 WNetGetConnection 获取本地或已连接的一个资源的网络名称 WNetGetLastError 获取网络错误的扩展错误信息 WNetGetUniversalName 获取网络一个文件的远程名称以及/或者UNC(统一命名规范)名称 WNetGetUser 获取一个网络资源用以连接的名字 WNetOpenEnum 启动对网络资源进行枚举的过程 2. API之消息函数 BroadcastSystemMessage 将一条系统消息广播给系统所有的顶级窗口 GetMessagePos 取得消息队列上一条消息处理完毕时的鼠标指针屏幕位置 GetMessageTime 取得消息队列上一条消息处理完毕时的时间 PostMessage 将一条消息投递到指定窗口的消息队列 PostThreadMessage 将一条消息投递给应用程序 RegisterWindowMessage 获取分配给一个字串标识符的消息编号 ReplyMessage 答复一个消息 SendMessage 调用一个窗口的窗口函数,将一条消息发给那个窗口 SendMessageCallback 将一条消息发给窗口 SendMessageTimeout 向窗口发送一条消息 SendNotifyMessage 向窗口发送一条消息 3. API之文件处理函数 CloseHandle 关闭一个内核对象。其包括文件、文件映射、进程、线程、安全和同步对象等 CompareFileTime 对比两个文件的时间 CopyFile 复制文件 CreateDirectory 创建一个新目录 CreateFile 打开和创建文件、管道、邮槽、通信服务、设备以及控制台 CreateFileMapping 创建一个新的文件映射对象 DeleteFile 删除指定文件 DeviceIoControl 对设备执行指定的操作 DosDateTimeToFileTime 将DOS日期和时间值转换成一个 win32 FILETIME 值 FileTimeToDosDateTime 将一个 win32 FILETIME 值转换成DOS日期和时间值 FileTimeToLocalFileTime 将一个FILETIME结构转换成本地时间 FileTimeToSystemTime 根据一个FILETIME结构的内容,装载一个SYSTEMTIME结构 FindClose 关闭由FindFirstFile函数创建的一个搜索句柄 FindFirstFile 根据文件名查找文件 FindNextFile 根据调用FindFirstFile函数时指定的一个文件名查找下一个文件 FlushFileBuffers 针对指定的文件句柄,刷新内部文件缓冲区 FlushViewOfFile 将写入文件映射缓冲区的所有数据都刷新到磁盘 GetBinaryType 判断文件是否可以执行 GetCompressedFileSize 判断一个压缩文件在磁盘上实际占据的字节数 GetCurrentDirectory 在一个缓冲区装载当前目录 GetDiskFreeSpace 获取与一个磁盘的组织有关的信息,以及了解剩余空间的容量 GetDiskFreeSpaceEx 获取与一个磁盘的组织以及剩余空间容量有关的信息 GetDriveType 判断一个磁盘驱动器的类型 GetExpandedName 取得一个压缩文件的全名 GetFileAttributes 判断指定文件的属性 GetFileInformationByHandle 这个函数提供了获取文件信息的一种机制 GetFileSize 判断文件长度 GetFileTime 取得指定文件的时间信息 GetFileType 在给出文件句柄的前提下,判断文件类型 GetFileVersionInfo 从支持版本标记的一个模块里获取文件版本信息

2,726

社区成员

发帖
与我相关
我的任务
社区描述
VFP,是Microsoft公司推出的数据库开发软件,用它来开发数据库,既简单又方便。
社区管理员
  • VFP社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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