zoukankan      html  css  js  c++  java
  • FindWindow和FindWindowEx函数使用

    FindWindow(
      lpClassName,        {窗口的类名}
      lpWindowName: PChar {窗口的标题}
    ): HWND;              {返回窗口的句柄; 失败返回 0}
    
    //FindWindowEx 比 FindWindow 多出两个句柄参数:
    FindWindowEx(
      Parent: HWND;     {要查找子窗口的父窗口句柄}
      Child: HWND;      {子窗口句柄}
      ClassName: PChar; {}
      WindowName: PChar {}
    ): HWND;
    {
    如果 Parent 是 0, 则函数以桌面窗口为父窗口, 查找桌面窗口的所有子窗口;
    如果  是 HWND_MESSAGE, 函数仅查找所有消息窗口;
    子窗口必须是 Parent 窗口的直接子窗口;
    如果 Child 是 0, 查找从 Parent 的第一个子窗口开始;
    如果 Parent 和 Child 同时是 0, 则函数查找所有的顶层窗口及消息窗口.
    }
    函数原型:HWND FindWindowEx(HWND hwndParent,HWND hwndChildAfter,LPCTSTR lpszClass,LPCTSTR lpszWindow)
     hwndParent:要查找子窗口的父窗口句柄。

        如果hwnjParent为NULL,则函数以桌面窗口为父窗口,查找桌面窗口的所有子窗口。

        Windows NT5.0 and later:如果hwndParent是HWND_MESSAGE,函数仅查找所有消息窗口。

        hwndChildAfter :子窗口句柄。查找从在Z序中的下一个子窗口开始。子窗口必须为hwndPareRt窗口的直接子窗口而非后代窗口。如果HwndChildAfter为NULL,查找从hwndParent的第一个子窗口开始。如果hwndParent 和 hwndChildAfter同时为NULL,则函数查找所有的顶层窗口及消息窗口。

        lpszClass:指向一个指定了类名的空结束字符串,或一个标识类名字符串的成员的指针。如果该参数为一个成员,则它必须为前次调用theGlobaIAddAtom函数产生的全局成员。该成员为16位,必须位于lpClassName的低16位,高位必须为0。

        lpszWindow:指向一个指定了窗口名(窗口标题)的空结束字符串。如果该参数为 NULL,则为所有窗口全匹配。返回值:如果函数成功,返回值为具有指定类名和窗口名的窗口句柄。如果函数失败,返回值为NULL。

    使用示例1:
    IntPtr ptrResult = FindWindow(null, "test");
    IntPtr ptrRadioButtonbox = FindWindowEx(ptrResult, IntPtr.Zero, "Button", "&8位");
    IntPtr ptrStartBtn = FindWindowEx(ptrResult, IntPtr.Zero, null, "确定");
    使用示例2:
    const int BM_CLICK = 0xF5;
    IntPtr maindHwnd = FindWindow(null, "QQ用户登录"); //获得QQ登陆框的句柄
    if (maindHwnd != IntPtr.Zero)
    {
        IntPtr childHwnd = FindWindowEx(maindHwnd, IntPtr.Zero, null, "登录");   //获得按钮的句柄
        if (childHwnd != IntPtr.Zero)
        {
            SendMessage(childHwnd, BM_CLICK, 0, 0);     //发送点击按钮的消息
        }
        else
        {
            MessageBox.Show("没有找到子窗口");
        }
    }
    else
    {
        MessageBox.Show("没有找到窗口");
    }
    
    
    

      

     
  • 相关阅读:
    86. Partition List
    2. Add Two Numbers
    55. Jump Game
    70. Climbing Stairs
    53. Maximum Subarray
    64. Minimum Path Sum
    122. Best Time to Buy and Sell Stock II
    以场景为中心的产品设计方法
    那些产品经理犯过最大的错
    Axure教程:如何使用动态面板?动态面板功能详解
  • 原文地址:https://www.cnblogs.com/marszhw/p/11087886.html
Copyright © 2011-2022 走看看