Hot to get second topmost window under cursor?

wenigtelefonier

Newcomer
Joined
Dec 4, 2007
Messages
3
Hi,

my applications consists of several Forms which can overlap each other. I can start actions by dragging and dropping a graphical element onto a form. The dragged element is actually represented by a form, too. To do this correctly I've got to know if the mouse cursor is above a visible part of the target form or if the target form is overlapped by another form at the current mouse cursor position.
I cannot use win32.WindowFromPoint. This would get me the handle of the topmost window, which normally would be what I'd like to have. But as I am dragging a From the "topmost" window is always the very Form which I am dragging. The target zone would then be the second topmost form under the mouse cursor. Do you have any idea how I can achieve this? Any help would be greatly appreciated.

Thank you.
David.
 
not quite clear about what you are saying though, a screenshot and a bit of explanation would help very much. but try splitting your windows, by using windows--> split
btw - a screenshot would really help to understand ur prob
 
Thanks raiden,

you're certainly right. I'll try to make myself clear with the attached screenshot.

OK. What I'm trying to do is dragging item (1) over window (2) and dropping it there. Window (2) which is my drop target is partly covered by window (3) which is not a drop target. Scince only visible parts of a potential drop target form should be valid drop targets, in my example the area (2a) would not be valid.

In order to identify my drop target I have got to find out which window (form) is currently visible under my mouse cursor.

Usually one would do that by calling Win32-API-function WindowFromPoint. In my case this won't work because the item (1) which I am dragging is actually a window (a form). Therefore WindowFromPoint will always return the handle of (1) because while dragging a form the topmost window under the mouse cursor is of course the dragged form itself.

What I am currently doing as a workaround is testing if the bounds of my potential drop target forms contain the current mouse cursor location. But this does not respect if the drop target form or parts of it are visible. So even if (2) was completely covered by another window and not visible at all, my current mechanism would return (2) as a valid drop target - which it wouldn't be because it would not be visible at that moment. With my current solution and the given screenshot example the entire area of form (2) would be a valid drop target - including (2a) which is not visible and which therefore must not be valid.

So how can I find out that in (2a) the form (2) is covered by another form? Or how can I find out that the mouse curser - would it be in (2a) - actually hovers form (3).

Thank you.
David.
 

Attachments

thanks for the speedy reply, but i have no idea how to do it, anyway ill ask my lecturer and my colleagues how to figure this out, and if i get a idea will post it. sorry again.....
 
YES.... exactly thanks plausibly Damp I totally agree with u, I did some digging on the net and asked my lecturers and colleagues even my lecturer said that GetWindow will help, ao there you go wenigtelefonier, hope you got ur answer.
 
Thanks to both of you. You really helped me a lot. Now at least I could implement something that helps to find out if my drag target form is covered by one of the windows of my own application.
Unfortunately I still cannot detect if a third-party application window is between the drag item and the target window at the mouse cursor position. In the attached screenshot you may see, what I mean. I want to drop the semi-transparent yellow item named "Andrea" onto on of the blue items. The hint you gave me works well if I want to drop the yellow item onto the shaded area of my application window "External Display". This is inhibited now, just as I want. But I still can drop the yellow item onto the part covered by the MSIE window.

Do you have another hint for me? Maybe it would help to know how you would get the window/form bounds from the IntPtr handle which is returned by GetWindow function. Today I'm doing

Code:
....
IntPtr nextWindowHandle = GetWindow(startHandle, (int)Win32.GW_HWNDNEXT);
if (nextWindowHandle!=(IntPtr)0){
  Control c = Control.FromHandle(nextWindowHandle);
  if (c!=null){
    Form nextForm = c.FindForm();
    if (nextForm!=null){
      if (nextForm.Bounds.Contains(p)){
        Console.WriteLine("window covers target");
      }
    }
  }
}
.....

I only get to "nextForm.Bounds.Contains(p);" for my application's own windows. I'm currently never detecting the shown MSIE window.

Cheers.
David.
 

Attachments

Last edited:
Back
Top