用WindowFromPoint()函数来获得鼠标所在位置的窗口的句柄--发生一个关闭窗口的消息---关闭鼠标所在的窗口

本文介绍了一个使用C++编写的简单程序,该程序能够获取鼠标当前位置,并不断尝试关闭该位置上的窗口。通过调用`GetCursorPos`和`WindowFromPoint`函数定位窗口,然后发送`WM_CLOSE`消息来实现这一功能。
#include "stdafx.h"
#include <Windows.h>

int _tmain(int argc, _TCHAR* argv[])
{
 POINT curpos;
 while (TRUE)
 {
  GetCursorPos(&curpos);
  HWND wnd = WindowFromPoint(curpos);
  SendMessage(wnd, WM_CLOSE, 0, 0);
  Sleep(1000);
 }
 
 return 0;
}

HWND WindowFromPoint(
  POINT Point
);
 
 
Return Value
  

Returns a handle to the window that contains the x-y coordinates to indicate success. Returns NULL to indicate that no window exists at the specified x-y coordinates.

//返回一个句柄,表示成功,返回NULL表示失败. 返回的这个窗口句柄是: 鼠标curpos结构体所在窗口里面的句柄被返回.

//句柄是一个整数.

Remarks


The WindowFromPoint function does not retrieve a handle to a hidden or disabled window, even if the x-y coordinate is within the window. To determine if child windows of a parent window contain an x-y coordinate, use the ChildWindowFromPoint function.

//这个函数不检索窗口被disabled的,不检索窗口被隐藏的,不返回这两个类型的句柄.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值