获取上次激活窗口的窗口句柄 [英] Get window handle of last activated window

查看:605
本文介绍了获取上次激活窗口的窗口句柄的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了坐落在系统托盘中,并可以执行在活动窗口中操作的应用程序。但是,单击系统托盘中的图标时, GetForegroundWindow()返回任务栏。我需要的是活跃在任务栏是之前的窗口。

I am developing an application that sits in the system tray and can perform actions on the active window. But when the icon in the system tray is clicked, GetForegroundWindow() returns the taskbar. I need to get the window that was active before the taskbar was.

我试着 EnumWindows的 GetWindow 枚举桌面窗口,但这往往转向了桌面小工具等顶级项目,凡不活跃最后一次。它甚至有可能,或当窗口被关闭的信息完全丢失?

I've tried enumerating the desktop window with EnumWindows and GetWindow, but this is often turning up desktop gadgets and other top items that where not active last. Is it even possible, or the information completely lost when the window is deactivated?

推荐答案

我想获得这些信息的唯一途径是通过安装一个系统全局钩子(的 WH_CALLWNDPROC相对=nofollow> SetWindowsHookEx函数)和捕捉所有的 WM_ACTIVATEAPP 。这甚至可以使您跟踪的全部历史,其中窗口是活跃的时候。

I think the only way to get that info is by installing a system wide hook (SetWindowsHookEx) on WH_CALLWNDPROC and capturing all WM_ACTIVATEAPP. This will even enable you to track the full history of which window was active when.

这篇关于获取上次激活窗口的窗口句柄的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆