|
Drag and Drop
Drag and Drop in TOutline
How to use the ItemAtPos to get DirListBox item
TOutLine drag and drop
Drag and drop
Drag and drop out of a TScrollBox
Drag & Drop
Drag and Drop in TOutline
Question
I've got a TOutline the onMouseDown contains BeginDrag(False) when a node is
expanded (onDblClick) my app dynamically adds children to the newly exposed
nodes.
Problem: after processing -- moving the mouse begins a drag operation.
Answer
A:
The problem is that before windows can proccess WM_MouseUp you have move the
mouse cursor. The solutions are :
1. Allow Windows to proceess mouse events as soon as possible:
OnMouseDown:
BeginDrag(False);
while ... do
begin
Application.ProccessMessages; { this allows Windows to
proceess messages }
{ a single step of processing }
end;
Comment:
Pay attention, while you are looping in 'while' user can do anything -
for example
close the application, so this solution requires more programming to
handle some
user actions differently while looping.
2. Similiar:
OnMouseDown:
BeginDrag(False);
Application.ProccessMessages;
while ... do
begin
{ a single step of processing }
end;
I don't know if it will work correctly - you have to check.
3. Move BeginDrag call to OmMouseMove event.
How to use the ItemAtPos to get DirListBox item
Question
I want to use Drag and Drop to move directory names from a TDirectoryListbox to a
TListbox where the list of directories that the user has chosen can be listed.
So far, all of the code is in place to allow OnDblClick to change the
contents of the label poiinted to in the DirLabel property and then add that
text ( the label's caption property ) to the awaiting TListbox.
Now, I've put the code in to allow the user to also drag an item from the
directory listbox to the regular listbox. And....here's my problem:
The drag begins in the MouseDown event handler for the DirectoryListbox by
checking to see if the user has pressed the mouse button down over the top
of a valid item...
if ItemAtPos( Point( X, Y ), True ) >= 0 then
BeginDrag( False );
Well, once the user has dragged the mouse over the TListbox and released the
mouse button, I want to go back to the TDirectoryListbox and get the
'string' and add it to the TListbox.
NOTE: if listbox this, and listbox that is beginning to confuse you ( I'm
getting dizzy just typing this in ) then what I want to do is drag a
directory name from a TDirectoryListbox and have it appear in the TListbox
when the user successfully completes the dragdrop operation.
Answer
A:
Just save the result of the ItematPos function in a variable in the form, then use that variable in the ListBoxDragDrop event. E.g.:
FDragItem:= ItematPos(X, Y, True);
if FDragItem >= 0 then
BeginDrag(false);
...
procedure TForm1.ListBoxDragDrop(Sender, Source: TObject; X, Y: Integer);
begin
if Source is TDirectoryListBox then
ListBox.Items.Add(TDirectoryListBox(Source).GetItemPath(FDragItem));
end;
TOutLine drag and drop
Question
How does one do Drag 'n Drop with a TOutLine. If I make the dragmode
dmAutomatic, then I cannot expand an item by clicking on it. I want both
features available. (i.e. Drag 'n Drop and to be able to click on an
item.)
Answer
A:
Set DragMode = dmManual, create an OnMouseDownHandler, inside the handler
call BeginDrag(False). BeginDrag(False) will not actually start dragging
until the user moves the mouse 5 pixels so if the user is simply clicking
then the drag operation will not begin.
Drag and drop
Question
1st problem:
I'm using the DragnDrop from Filemanager with the API "DragAcceptFiles(Handle,
True)" which works fine. But I want to Drop the File(s) / Dir(s) into an
Outline. So I need to (somehow) detect when the Mouse is moved over my
Application so that I can Select on which Outline Node to drop it. As soon as
my App looses the Focus I can't track any mouse movements! Must be an API
that lets me do this, right?
2nd problem:
How do you do the reverse? (dragnDrop to Filemanager)
Answer
A:
What you need to do is trap the wm_DropFiles message in the TOutline
component. This will require creating a descendant of it. You should also
make sure that TOutline's Handle is the one you're passing to
DragAcceptFiles. You can tell where the mouse is at the time of the drop by
using DragQueryPoint. If you read the help in WINAPI.HLP on DragAcceptFiles,
wm_DropFiles, DragQueryFile, DragQueryPoint, and DragFinish, you should be
able to figure out how that all works.
Drag and drop out of a TScrollBox
Question
I have a TScrollBox in which I load (in runtime) a variable quantity of TImage.
-> to drag a picture from the ScrollBox and drop it in an other frame (Form2)
1. I can't access to TImage because I don't know in which picture the user
clicks.
2. I don't know where I could write my methods dragdrop dragover etc ...
because my pictures are created at runtime.
Answer
A:
You can write a generic function for a single TImage, and assign that method
to each dynamically created TImage, thus:
procedure TForm1.GenericMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
TImage(Sender).BeginDrag(False);
{other stuff you might want to do}
end;
{....}
UmpteenthDynImage := TImage.Create(dummyImage);
UmpteenthDynImage.MouseDown := TForm1.GenericMouseDown;
This should be syntactically close. You can just assign each dynamic object
the GenericMouseDown method, and they'll all use it. The dummyImage owner
allows all dynamic objects to easily be destroyed by just destroying the
dummyImage.
Drag & Drop
Question
I want to be able to drag an application (from say the desktop in
W95, or from Program Manger in w3.11) into a Delphi app, so that the
delphi app can then extract the dragged application's icon and path.
Answer
A:
To handle drag/drop from File Manager, you "register" by passing your
form's window handle (the Handle property) to the Windows API function
DragAcceptFiles(Handle, True);
You will now receive a WM_DROPFILES message when files are dropped on your
form from File Manager. To stop accepting files, call the function again
with False as the second parameter.
You'll use the Windows functions DragQueryFile to get at the dropped
filenames, and DragFinish to dispose of the information when done.
DragQueryPt tells you where on your form files were dropped.
If you need to accept files even when minimized, you'll have to add an
OnMessage handler for the main Application object too. Here's an example
program - create a form containing a list box with Align set to alClient,
and copy appropriate parts of the following into the code:
...
{ Private declarations }
procedure WMDropFiles(VAR Msg: TWMDropFiles);
message WM_DROPFILES;
procedure AppOnMessage(VAR Msg: TMsg;
VAR Handled : Boolean);
...
implementation
USES ShellApi;
...
procedure TForm1.WMDropFiles(VAR Msg: TWMDropFiles);
VAR
N : Word;
buffer : ARRAY[0..80] OF Char;
BEGIN
WITH Msg DO
BEGIN
FOR N := 0 TO DragQueryFile(Drop, $FFFF, buffer, 80)-1 DO
BEGIN
DragQueryFile(Drop, N, Buffer, 80);
ListBox1.Items.Add(StrPas(Buffer));
END;
DragFinish(Drop);
END;
END;
procedure TForm1.AppOnMessage(VAR Msg: TMsg;
VAR Handled : Boolean);
VAR WMD : TWMDropFiles;
BEGIN
IF Msg.message = WM_DROPFILES then
BEGIN
MessageBeep(0);
WMD.Msg := Msg.message;
WMD.Drop := Msg.wParam;
WMD.Unused := Msg.lParam;
WMD.Result := 0;
WMDropFiles(WMD);
Handled := TRUE;
END;
END;
procedure TForm1.FormCreate(Sender: TObject);
begin
DragAcceptFiles(Handle, True);
DragAcceptFiles(Application.Handle, True);
Application.OnMessage := AppOnMessage;
end;
A:
To drag and drop from the desktop or Explorer or FileManager you have
yo use the WM_DROPFILES messsage, if you want an example of this,
drop me a line and I'll send you one..
The trouble with the desktop in Win95 is that the files are .lnk
files, so you can't get any useful info out of it easily.
There's a component on the Delphi Super page that allows you to get
at all the propertiues stored in the .lnk, well worth a look. I can't
remeber what is called but do a search for "lnk" and you should find
it.
|