tags:

views:

495

answers:

5

Hello, I need to create a transparent overlay window, that goes above another window. The other window is from another vendor. And when the user drags that window mine needs to follow.

WS-CHILD seems like a nice idea but it cannot be combined with WS-EX-LAYERED, which I really need (for transparency). But I still can set a parent without using WS-CHILD.

Parenting does give my winproc notifications (WM-WINDOWPOSCHANGING), but only after dragging is complete, on mouse-up. To give a nice feeling i need to get those notifications (or for example WM-MOVE) continuosly while dragging.

I guess my problem is similar to docking, but the fine docking solution seen fx at CodeProjet uses WS-CHILD. ( http://www.codeproject.com/KB/toolbars/dockwnd.aspx )

I guess I could use polling but that is not what I am looking for. Also I could use ::SetWindowsHook(). But that is my final resort. I am hoping I have missed something trivial and that somebody can point me in a good direction.

Thanx

+2  A: 

I know it is not your preferred solution, but I think you need to use a global mouse hook. Pass WH_MOUSE_LL to SetWindowsHookEx() and do nothing in the default case of your low-level mouse proc. But when you get the WM_WINDOWPOSCHANGING notification, start tracking the mouse movements and making appropriate calls to MoveWindow() or whatever.

Phil Booth
Thanks for caring, but I prefer to avoid hooks. And please remember that when you post a response to anything, that question will stop appearing as unanswered for everybody after you.
Adam
Actually, an unanswered question is one with no accepted answer or no upvoted answer. Until an answer is upvoted, the question will appear somewhere in the Unanswered tab. It seems like phil.booth has honestly tried to help, and you've slapped him for it.
RBerteig
I didn't know that. So, I owe Phil an apology for my wry words. Sorry Phil.But still, of course I can use hooks, but I explicitly asked for a solution without hooks.
Adam
A: 

How about WM_MOVING message? You may try intercepting this message and move your window accordingly.

Canopus
I have checked all messages with a spy tool. The only message that reaches my process from the other one is WM_WINDOWPOSCHANGING. And only after mouse-up.
Adam
A: 

If you want to know when a window in another process is being moved or sized, you need to install a hook,catch the WM_MOVING and WM_SIZING messages and reflect those messages back to your controller process. Sorry it's not the answer you want! I don't blame you for wanting to avoid cross process hooks, its a bit of a pain...

Mo Flanagan
A: 

Hi Adam!

I have the same problem...let's work together. I did not solve it, too...until now. I'm sure it works without hooks. The positioning is no problem in my application...my transparent window is always visible and on top of another window...only the activating and focussing of the above is a tricky...

contact me...

For me focusing and activating is no problem. When I do CreateWindowEx() then I set the other process' window as parent, but I do not use WS_CHILD. However my problem is positioning. How did you manage window positioning across processes ?
Adam
A: 

Hi Adam! I use a LayeredWindow for that and set the other window as parent.

This is the code i used for that:

::SetWindowLong(GetHwnd(), GWL_EXSTYLE, GetWindowLong(GetHwnd(), GWL_EXSTYLE) |WS_EX_LAYERED); ::SetLayeredWindowAttributes(GetHwnd(), RGB(255,0,255), 255, LWA_COLORKEY | LWA_ALPHA); ::SetWindowLongPtr(GetHwnd(),GWLP_HWNDPARENT,(long)GetParentHWND()); ::SetWindowPos(hndOtherWindow, hndOverlayWinow, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |SWP_NOACTIVATE);

It works for my purposes. There's only one problem left: If my overlaying window losts the focus i want to set the focus, or activate the other window. Do you have an idea?

Greetz

Hi Jens,I am basically doing the same thing (but I set the parent and layered style directly in CreateWindowEx().) **Are your two windows really in two different processes? And the layered child really follows the movements of the background window??** For me it does not.Sorry I cannot help you on the focus bit, in my sceanario focus does not become a problem.
Adam