WIN API-VFP获取第三方窗体的控件信息(句柄,窗口ID,进程ID,类名,标题)

*十豆三 2010-02-09

 
*函数返回与指定字符创相匹配的窗口类名或窗口名的最顶层窗口的窗口句柄。这个函数不会查找子窗口。
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 &&获得指定窗口所属的类的类名

*函数将指定的消息发送到一个或多个窗口。此函数为指定的窗口调用窗口程序,直到窗口程序处理完消息再返回。而函数PostMessage不同,将一个消息寄送到一个线程的消息队列后立即返回。
Declare Long SendMessage In WIN32API Long HWnd,Long Msg,Long wParam,String @IParam

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

vfp9.0调用API制作照相软件实例 PUBLIC WM_CAP_DRIVER_DISCONNECT PUBLIC hwndc,WM_CAP_SAVEDIB,WM_CAP_FILE_SET_CAPTURE_FILEA,WM_CAP_SEQUENCE,WM_CAP_STOP DECLARE INTEGER capCreateCaptureWindowA IN "AVICAP32.DLL" STRING lpszWindowName ,INTEGER dwStyle , INTEGER x, INTEGER Y, INTEGER nWidth ,INTEGER nHeight,INTEGER ParentWin,INTEGER nId DECLARE INTEGER SendMessage IN "user32" INTEGER HWND, INTEGER wmsg,INTEGER wpar1, INTEGER wpar2 DECLARE INTEGER SendMessage IN "user32" AS SendMessageA INTEGER HWND, INTEGER wmsg,INTEGER wpar1, STRING wpar2 *!* 显示: WM_USER = 1024 WM_CAP_START = WM_USER WM_CAP_STOP = WM_CAP_START + 68 WM_CAP_DRIVER_CONNECT = WM_CAP_START + 10 WM_CAP_DRIVER_DISCONNECT = WM_CAP_START + 11 WM_CAP_SAVEDIB = WM_CAP_START + 25 WM_CAP_GRAB_FRAME = WM_CAP_START + 60 WM_CAP_SEQUENCE = WM_CAP_START + 62 WM_CAP_FILE_SET_CAPTURE_FILEA = WM_CAP_START + 20 WM_CAP_SEQUENCE_NOFILE =WM_CAP_START+ 63 WM_CAP_SET_OVERLAY =WM_CAP_START+ 51 WM_CAP_SET_PREVIEW =WM_CAP_START+ 50 WM_CAP_SET_CALLBACK_VIDEOSTREAM = WM_CAP_START +6 WM_CAP_SET_CALLBACK_ERROR=WM_CAP_START +2 WM_CAP_SET_CALLBACK_STATUSA= WM_CAP_START +3 WM_CAP_SET_CALLBACK_FRAME= WM_CAP_START +5 WM_CAP_SET_SCALE=WM_CAP_START+ 53 WM_CAP_SET_PREVIEWRATE=WM_CAP_START+ 52 hWndC = capCreateCaptureWindowA('My Own Capture Window',1342177280,0,0,200,150,THISFORM.HWND ,0) &&显示大小 IF hWndC 0 SendMessage(hWndC, WM_CAP_SET_CALLBACK_VIDEOSTREAM, 0, 0) SendMessage(hWndC, WM_CAP_SET_CALLBACK_ERROR, 0, 0) SendMessage(hWndC, WM_CAP_SET_CALLBACK_STATUSA, 0, 0) SendMessage(hWndC, WM_CAP_DRIVER_CONNECT, 0, 0) SendMessage(hWndC, WM_CAP_SET_SCALE, 1, 0) SendMessage(hWndC, WM_CAP_SET_PREVIEWRATE, 66, 0) SendMessage(hWndC, WM_CAP_SET_OVERLAY, 1, 0) SendMessage(hWndC, WM_CAP_SET_PREVIEW, 1, 0) * THISFORM.ACTIVATE ENDIF
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值