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, . , . , .