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:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    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("没有找到窗口");
    }
  • 相关阅读:
    Idea初始化Vue项目
    为什么在vue的组件中,data要用function返回对象呢
    SpringBoot+RabbitMQ 快速入门
    Neo4j入门-CQL
    记一次坑爹的websocket Response code was not 101: 404的问题
    Neo4j入门-开始使用
    关于乱码问题的一些思考
    搭建apache2.4+php7+mysql+phpmyadmin
    oracle dba 关闭 002
    oracle 正则表达式 非字母 非数字
  • 原文地址:https://www.cnblogs.com/ximi07/p/11936784.html
Copyright © 2011-2022 走看看