[原创分享]VFP获取第三方窗体的控件信息(句柄,窗口ID,进程ID,类名,标题),该怎么解决
[原创分享]VFP获取第三方窗体的控件信息(句柄,窗口ID,进程ID,类名,标题)
本人水平太菜,不要见笑,如果欠佳之处,请帮忙指出。
如果您有更合理、更简洁的代码,希望您能与大家分享,谢谢。
------解决方案--------------------
------解决方案--------------------
------解决方案--------------------
版主,你实在是太过谦了。
本人水平太菜,不要见笑,如果欠佳之处,请帮忙指出。
如果您有更合理、更简洁的代码,希望您能与大家分享,谢谢。
- VB code
Declare Long FindWindow In WIN32API String lpClassName,String lpWindowName &&函数返回与指定字符创相匹配的窗口类名或窗口名的最顶层窗口的窗口句柄。这个函数不会查找子窗口。 Declare Long FindWindowEx In WIN32API Long hwndParent,Long hwndChildAfter,String @lpszClass,String @lpszWindow &&函数获得一个窗口的句柄,该窗口的类名和窗口名与给定的字符串相匹配。这个函数查找子窗口,从排在给定的子窗口后面的下一个子窗口开始。在查找时不区分大小写。 Declare Long GetClassName In WIN32API Long HWnd,String @lpClassName,Long nMaxCount &&获得指定窗口所属的类的类名 Declare Long SendMessage In WIN32API Long HWnd,Long Msg,Long wParam,String @IParam &&函数将指定的消息发送到一个或多个窗口。此函数为指定的窗口调用窗口程序,直到窗口程序处理完消息再返回。而函数PostMessage不同,将一个消息寄送到一个线程的消息队列后立即返回。 Declare Long GetDlgCtrlID In WIN32API Long hwndCtl &&通过句柄得到控件ID Declare Long GetWindowThreadProcessId In WIN32API Long HWnd,Long @lpdwProcessId &&通过窗口句柄返回其进程Id #Define WM_GETTEXT 0x000D Create Cursor T1 (序号 I Not Null Autoinc,父窗口句柄 I,窗口句柄 I,窗口ID I,进程ID I,窗口类名 C(100),标题文本 C(254)) ****** Declare Long WinExec In kernel32 String lpCmdLine,Long nCmdShow &&运行指定的程序 =WinExec("C:\WINDOWS\system32\calc.exe",1) &&以 计算器 为例 m.lcCaption="计算器" &&要查找窗口的标题,这里以 计算器为例 ****** Local m.lnHandle,m.lcClassName,m.lcText,m.lnClassLen,m.lnTextLen,m.lnProcessId,m.lnChildHandle,m.lnMaxXH m.lnHandle=FindWindow(Null,m.lcCaption) If m.lnHandle>0 Store Replicate(Chr(0),255) To m.lcClassName,m.lcText m.lnClassLen=GetClassName(m.lnHandle,@m.lcClassName,255) m.lnTextLen=SendMessage(m.lnHandle,WM_GETTEXT,255,@m.lcText) m.lnProcessId=0 =GetWindowThreadProcessId(m.lnHandle,@m.lnProcessId) Insert Into T1 (父窗口句柄,窗口句柄,窗口ID,进程ID,窗口类名,标题文本) Values (0,m.lnHandle,0,m.lnProcessId,Left(m.lcClassName,m.lnClassLen),Left(m.lcText,m.lnTextLen)) &&顶层窗口没有ID Store 0 To m.lnChildHandle,m.lnMaxXH Do While .T. Select * Into Cursor T2 From T1 Where 序号>m.lnMaxXH If _Tally>0 Release m.lnMaxXH Select Max(序号) As MaxXH Into Array lnMaxXH From T1 Select T2 Scan m.lnHandle=窗口句柄 m.lnChildHandle=0 Do While .T. m.lnChildHandle=FindWindowEx(m.lnHandle,m.lnChildHandle,Null,Null) If m.lnChildHandle<>0 Store Space(255) To m.lcClassName,m.lcText m.lnClassLen=GetClassName(m.lnChildHandle,@m.lcClassName,255) m.lnTextLen=SendMessage(m.lnChildHandle,WM_GETTEXT,255,@m.lcText) m.lcCtrlId=GetDlgCtrlID(m.lnChildHandle) m.lnProcessId=0 =GetWindowThreadProcessId(m.lnHandle,@m.lnProcessId) Insert Into T1 (父窗口句柄,窗口句柄,窗口ID,进程ID,窗口类名,标题文本) Values (m.lnHandle,m.lnChildHandle,m.lcCtrlId,m.lnProcessId,Left(m.lcClassName,m.lnClassLen),Left(m.lcText,m.lnTextLen)) Loop Else Exit Endif Enddo Endscan Else Exit Endif Enddo Select T1 Locate Browse Else Messagebox("没有找到 ["+m.lcCaption+"] 窗体!"+Space(5),48,"信息提示") Endif Clear Dlls Release m.lnHandle,m.lcClassName,m.lcText,m.lnClassLen,m.lnTextLen,m.lnProcessId,m.lnChildHandle,m.lnMaxXH
------解决方案--------------------
------解决方案--------------------
------解决方案--------------------
版主,你实在是太过谦了。