Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 257
  • Last Modified:

Drag & Drop / Copy & Move (Respond to control key presses...)

Hi Guys.

I have an app that does drag & Drop. It works great. It looks somewhat like the windows folder explorer. I can move files from folders to folders.

Now I want to add the capability to respond to the Control key to change the behavior from copy to move (i.e. with CONTROL it copes, without CONTROL it moves). Like in many applications.

It seems like quite a common thing to do, but I'm not sure how to do it.

In my app, I have OnStartDrag in the "files" listbox, and then I put the file's ID as the DragObject. The cursor is changed automatically to the "drag" cursor.

Pretty simple so far. But now I'm baffled on how to proceed... how can I intercept the press/depress on Control while draging? I guess I can do it on the dragged-to object (The folders list) only. And then somehow change the cursor and remember that the CONTROL is pressed?

Any advice before I start tackling this?

Ron.
0
mertero
Asked:
mertero
1 Solution
 
andrewjbCommented:
You probably want to catch it in the DragDrop event when you let go...

(Look at explorer - you can change whether shift/ctl are pressed as you drag a file)

To change the cursor as you go... doesn't the source of the drag/drop keep getting MouseMove events as you drag? (Even after the mouse has left the boundary of the component)... so you can check the button state in MouseMove, if you're dragging, and change the cusros there?
0
 
kretzschmarCommented:
take a look into my solution at
http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_20407731.html#7873367

your needed part from there (in procedure SetTreeItemTypeSet):

....
  //First do as want to Move
  Result := [ddtMove];
  //Get Shift Key
  if (GetAsyncKeyState(VK_SHIFT) OR $FFFF) = -1 then
    Result := Result + [ddtSort] - [ddtMove];

  //Get Control Key
  if (GetAsyncKeyState(VK_CONTROL) OR $FFFF) = -1 then
    Result := Result + [ddtCopy] - [ddtMove];
.....

hope you get it

meikl ;-)

0
 
merteroAuthor Commented:
Thanks guys.

I had to do some tweaking myself (Chagne the dragged OBJECT was the key) but you got me started in the right direction.

Cheers,

M.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now