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

 

转载于:https://www.cnblogs.com/dongling/p/5571144.html

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值