HWND creation time

I am new to this community, working with one of my script automation tools. I ran into a problem, I wanted to get HWND creation time.

I have a set of HWNDs in an array that I got from FindWindowEx, I want to find in an array which HWNDs are created last depending on the system time

I don’t have enough knowledge about window hooks, but I read about some CBTproc that have some kind of event called “CBT_CREATEWND” that can return HWND during window creation, I’m very unsure how to work with window hooks But if I get HWND, I can pick up the system time and compare with the HWND of my array.

Anyone can shed light on the same, and also ask me in more detail if I do not understand.

Thank you Manish Bansal

+5
source share
1 answer

Windows does not save this information in a way that is accessible through the API, so you need to collect it yourself.

If you can change the code that creates the HWND, you can just save the current time when processing WM_CREATE or WM_NCCREATE.

I would avoid window hooks, if possible - they embed your DLL in every process that creates windows. A critical error in your DLL will cause every desktop application to die from a terrible death.

If you need to log in using the windows hook, you add the hook using SetWindowsHookEx as follows:

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

Then your hook will 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);
}

proc DLL, . , . , .

+5

All Articles