zoukankan      html  css  js  c++  java
  • WIN APIVFP获取第三方窗体的控件信息(句柄,窗口ID,进程ID,类名,标题

    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 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

  • 相关阅读:
    up6-chrome 45+安装教程
    HttpUploader7-授权码配置
    jsp-MySQL连接池
    WordPaster2-正式包布署说明
    HTTP文件上传插件开发文档-ASP
    HTTP文件上传插件开发文档-JSP
    eWebEditor9.x整合教程-Xproer.WordPaster
    42. Trapping Rain Water
    41. First Missing Positive
    40. Combination Sum II
  • 原文地址:https://www.cnblogs.com/hdl217/p/1895322.html
Copyright © 2011-2022 走看看