• Windows API 编程----EnumWindows()函数的用法


    1.

    函数原型:

    BOOL WINAPI EnumWindows(
    _In_ WNDENUMPROC lpEnumFunc,
    _In_ LPARAM lParam
    );

    lpEnumFunc: 应用程序定义的回调函数的指针

    lParam:         传递给回调函数的应用程序定义的值

    MSDN中对EnumWindows的解释:

    Enumerates all top-level windows on the screen by passing the handle to each window, in turn, to an application-defined callback function. EnumWindows continues until the last top-level window is enumerated or the callback function returns FALSE.

    即:

    枚举屏幕上的所有的顶层窗口,轮流地将这些窗口的句柄传递给一个应用程序定义的回调函数。EnumWindows会一直进行下去,直到枚举完所有的顶层窗口,或者回调函数返回了FALSE.

    2.

    EnumWindowsProc()函数的定义:

    BOOL CALLBACK EnumWindowsProc(
    _In_ HWND hwnd,
    _In_ LPARAM lParam
    );

    hwnd: 在枚举每个顶层窗口而调用该函数的过程中传递给该函数的顶层窗口的句柄

    lParam: 即EnumWindows()函数的第二个参数。

    Return Value:

    返回TRUE,则EnumWindows()函数在系统中继续调用EnumWindowsProc()函数;返回FALSE,则停止枚举。

    MSDN解释:

    An application-defined callback function used with the EnumWindows or EnumDesktopWindows function. It receives top-level window handles. The WNDENUMPROC type defines a pointer to this callback function. EnumWindowsProc is a placeholder for the application-defined function name

    即:

    应用程序定义的函数,用于EnumWindows()或EnumDesktopWindos()函数。接收顶层窗口句柄。WNDENUMPROC类型定义了指向这种回调函数的指针。EnumWindowsProc是一个应用程序定义的函数名称的占位符。

    应用举例:

    //这段代码的功能就是枚举当前所有的顶层窗口句柄,并且指定了一个窗口句柄,如果枚举到的顶层窗口句柄和传递给EnumWindowsProc函数的窗口句柄不同,则使枚举到的顶层窗口失能

    //
    自定义结构体 typedef struct _DLONG { LONG wParam; LONG lParam; }stLONG; //回调函数的定义 BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam) { stLONG *pDlong = (stLONG*)lParam; BOOL bEnable = (BOOL)pDlong->lParam; if (hwnd != (HWND)pDlong->wParam)   EnableWindow(hwnd, bEnable);//如果当前所枚举到的顶层窗口句柄和主调函数(EnumWindos函数)所传递来的额外信息做指定的顶层窗口句柄不同,则进行相关使能或使失能操作 return TRUE; } ...... stLONG dlong; //传递给EnumWindowsProc的额外信息 dlong.lParam = (LPARAM)FALSE; dlong.wParam = (WPARAM)hWnd; EnumWindows(EnumWindowsProc, (LONG)&dlong);
  • 相关阅读:
    面试题示例
    软件测试面试题(简答)
    278. 第一个错误的版本 领扣
    hbase搭建web项目 报500错误 HTTP Status 500
    java API连接虚拟机上的hbase
    java程序连接hive数据库遇到的问题
    java程序向hdfs中追加数据,异常以及解决方案
    创建一个简单的maven的web程序
    java连接hbase时出现....is accessible from more than one module:
    导师双选制系统
  • 原文地址:https://www.cnblogs.com/dongling/p/5571144.html
Copyright © 2020-2023  润新知