Click here to Skip to main content
15,888,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a small problem, i am trying to drop some file from my application to outside of the application, here how i can get the cursor position when it goes outside of the application, i used getcursorposition, but with that coordinate i can't able to identify it is in my application or not.
Posted
Updated 7-Jan-16 1:01am
Comments
Jochen Arndt 7-Jan-16 7:24am    
To check if the position is on your application, just get the screen coordinates of your main window and compare with the cursor position.

If the operation is a common drag & drop operation you should not care about. Then the receiving window should handle the drop event and the drag function will return a corresponding value.
Vijay533 7-Jan-16 8:26am    
I should able to drop it outside of the application, but if i drop the file in my application also the drop function is triggering.
Jochen Arndt 7-Jan-16 10:27am    
That can't be achieved by using the mouse position.

It is always the destination app/window that decides if dropping is allowed.

When using common Drag & Drop and the other application supports it, it will be dropped there. There is no need to know where that occurs.

If your application supports dropping too and you don't want to drop files dragged from your own app, just set some kind of flag indicating this (set the flag just before calling DoDragDrop and clear it afterwards; in your OnDragEnter and OnDragOver handlers return DROPEFFECT_NONE when the flag is set).

You know you might convert screen coordinates to client ones (or viceversa).
As an alternative, you might detect when the mouse pointer 'exits' from your application window (see WM_MOUSELEAVE message[^]).
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 7-Jan-16 10:06am    
Hm... It's not yet solve the problem (and why WM_MOUSELEAVE can be an alternative, to what?)
The problem is: when the mouse is leaving, you can get the coordinates at this moment of time (usually, a little later moment). Then what? Then the window won't respond to any mouse events.

What the user really needs (usually), is the mouse capture. Please see Solution 2.

—SA
CPallini 7-Jan-16 15:57pm    
Alternative to GetCursorPos, of course.
Sergey Alexandrovich Kryukov 7-Jan-16 16:25pm    
I see, thank you for the clarification. Still, the problems I pointed out remain valid. In such cases, mouse capture is critically important.
In the APIs where capture is not available, the known technique is handling the event in the "bigger" parent element.

This is a usual but serious problem. You can implement, for example, drag behavior without capture. It will "almost work", which is bad. Why almost? The behavior depends on how quickly you move the mouse. If you far from the boundaries and move slowly, the control follows the mouse. But if you move faster, the mouse cursor "jumps out" away from the client area before the window can follow it, and handling get lost. With capture, the handling still works, because the events are dispatched to the window which has the capture, even if the mouse cursor is outside it. Without the capture, no matter what you do in WM_MOUSELEAVE handler, you cannot respond to mouse events outside the window.

—SA
Vijay533 8-Jan-16 0:09am    
Is there any way can i get the path based on cursor position, what i mean suppose i open 3 folders like D:\vijay\temp, c:\system\data, E:\data\directory , so if i move the mouse from 1st directory to second directory can i get the directory path?, based on cursor position.
You can get the position of the mouse cursor, no matter where it is. To transform the coordinates in the coordinate system of your window, you can use the screen coordinates of your window.

But the problem is: what event would trigger your code? You respond to mouse events outside of your application, you would need to capture the mouse. This is how:
SetCapture function (Windows)[^],
ReleaseCapture function (Windows)[^],
GetCapture function (Windows)[^].

See also my comment to Solution 1.

—SA
 
Share this answer
 
v2
Comments
Vijay533 8-Jan-16 0:37am    
Is there any way can i get the path based on cursor position, what i mean suppose i open 3 folders like D:\vijay\temp, c:\system\data, E:\data\directory , so if i move the mouse from 1st directory to second directory can i get the directory path?, based on cursor position.
Sergey Alexandrovich Kryukov 8-Jan-16 12:07pm    
This is an irrelevant question. Did you understand my solution, which gives you all you need to know, as related to your original question? Are you going to accept this answer formally?

You can then ask a separate question about paths, but please provide appropriate detail.

—SA
C#
Thank you every one i get the solution for this.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900