HWND 创建时间 [英] HWND Creation Time

查看:29
本文介绍了HWND 创建时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是这个社区的新手,在使用我的自动化脚本 1 时遇到问题,我想获得 HWND,创建时间.

I am new to this community, while working with 1 of my automation script I am encountering an issue, I wanted to get HWND’s, creation time.

我在从 FindWindowEx 检索到的数组中有一组 HWND,我想根据系统时间在数组中找到最后创建的 HWND

I am having a set of HWND in an array which I have retrieved from FindWindowEx, I want to find in array which HWND is created last depending upon system time

我对窗口钩子没有足够的了解,但我读到了一些 CBTproc,它有一些名为CBT_CREATEWND"的事件,它可以在窗口即将创建时返回 HWND,我非常不确定如何使用窗钩但是如果我得到 HWND,我可以获取系统时间并与我的阵列的 HWND 进行比较.

I do not have enough knowledge of window hooks, but I read about some CBTproc which has some event called "CBT_CREATEWND" which can return HWND at the time window is about to create, I am very much unsure about how to work with window hooks But if I will get HWND I can pick up system time and compare with HWND of my array.

任何人都可以对此有所了解,如果我不清楚,也可以问我更多详细说明.

Anyone can please put some light on the same, also ask me for more elaboration if I am not clear.

谢谢,曼尼什·班萨尔

推荐答案

Windows 不会以可通过 API 访问的方式存储此信息,因此您必须自己收集.

Windows doesn't store this information in a way that is accessible via the API, so you have to gather it yourself.

如果您可以修改创建 HWND 的代码,您可以在处理 WM_CREATE 或 WM_NCCREATE 时只存储当前时间.

If you can modify the code that creates the HWND, you can just store the current time while handling WM_CREATE or WM_NCCREATE.

如果可能的话,我会避免使用窗口挂钩 - 它们会将您的 DLL 注入到每个创建窗口的进程中.您的 DLL 中的一个严重错误将导致您桌面上的每个应用程序都死亡.

I'd avoid window hooks if possible - they inject your DLL into every process that is creating windows. A critical bug in your DLL will cause every app on your desktop to die a horrible death.

如果你必须使用 windows 钩子,你可以使用 SetWindowsHookEx 注入钩子 像这样:

If you have to go to with windows hook, you inject the hook using SetWindowsHookEx like this:

HHOOK myHook = SetWindowsHookEx(WH_CBT, MyHookFunction, myHookDll, 0);

您的钩子过程将如下所示:

Your hook proc will then look like this:

LRESULT CALLBACK MyHookFunction(int nCode, WPARAM wParam, LPARAM lParam)
{
   if (nCode == HCBT_CREATEWND)
   {
        // wParam is new window.
   }
   else if (nCode == HCBT_DESTROYWND)
   {
        // wParam is window being destroyed
   }

   return CallNextHookEx(myHook, nCode, wParam, lParam);
}

hook proc 需要存在于 DLL 中,因此它可以被其他进程加载.由于您的钩子将在不同的进程中运行,您需要将信息编组回您的原始进程.例如,您可以通过自定义窗口消息执行此操作.

The hook proc needs to be present in a DLL, so it can be loaded by other processes. Since your hook will be running in different processes, you'll need to marshal the information back to your original process. You could do this via a custom window message, for example.

这篇关于HWND 创建时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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