I need to attach a transparent, layered window to any application window present in the system, with the added feature of the user not losing the keyboard focus.
So I went with the owner method: use GetWindowLongPtr with GWLP_HWNDPARENT and tracking the owner movement with a simple out of context hook (SetWinEventHook).
Also, using WS_EX_NOACTIVATE on my owned window I let the user to continue working without losing the focus due to the window that is attaching.
The problem appears when I want to attach my 'owned' window to another window which is not in the foreground. In this case, the user does not get the focus removed, but the owned window appears at the top of the Z Order (above the window the user is currently using).
I tried to make the ZOrder of the owned window to be on-top of the owner (below the window the user is working on):
SetWindowLongPtr(hwnd, GWLP_HWNDPARENT, (LONG_PTR) parentHandle));
SetWindowPos(hwnd,parentHandle,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE);
This makes not only the Z-Order of the owned window to change, but the owner gets activated also.
I tried the SWP_NOOWNERZORDER flag, without success.
There's some workaround without using some hooking on the target window procedure to make the ZOrder change in the owned window ?