Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 29-12-2011
jplj jplj is offline
Miembro
 
Registrado: oct 2003
Posts: 189
Poder: 21
jplj Va por buen camino
Arrastrar y soltar "fuera" de delphi.

Hola:

Lo que pretendo es arrastrar y soltar un fichero fuera -Escritorio, editor de texto, programa de correo, ...- de la aplicación.

En concreto: en la aplicación tengo un TListBox con el nombre de algunos de los fichero que están almacenados en una carpeta. Quiero que el usuario pueda arrastrar desde el TListBox al Escritorio, editor de texto, ... el fichero que está representado por su nombre en el TListBox. Igual que cuando, por ejemplo, desde Lotus Notes arrastramos y soltamos en el Escritorio un fichero que lleva anexado el correo.

Muchas gracias de antemano.
Y Felices Fiestas.
__________________
Sonríe. Mañana puede ser peor.
Responder Con Cita
  #2  
Antiguo 30-12-2011
Avatar de newtron
[newtron] newtron is offline
Membrillo Premium
 
Registrado: abr 2007
Ubicación: Motril, Granada
Posts: 3.462
Poder: 21
newtron Va camino a la fama
Hola.

Imagino que dependiendo lo que quieras hacer con el archivo, si abrirlo, copiarlo al escritorio, etc. tendrás que ejecutar una acción u otra. Si es abrirlo puedes usar el comando "ShellExecute" para abrirlo el archivo con el programa que tenga predeterminado windows para ello. Para copiarlo al escritorio imagino que lo más simple es copiarlo desde su ubicación original a la carpeta de windows donde se ubica lo que hay en el escritorio (que ahora mismo no recuerdo cual es) y te aparecerá directamente.

Espero haberte dado alguna idea.

Saludos
__________________
Be water my friend.
Responder Con Cita
  #3  
Antiguo 30-12-2011
jplj jplj is offline
Miembro
 
Registrado: oct 2003
Posts: 189
Poder: 21
jplj Va por buen camino
Hola newtron.

Cita:
Imagino que dependiendo lo que quieras hacer con el archivo, si abrirlo, copiarlo al escritorio, etc. tendrás que ejecutar una acción u otra.
He ahí la cuestión, que no sé de antemano lo que quiere hacer el usuario. Dependerá de dónde suelte el "archivo", si es en el Escritorio sería copiarlo, pero si lo hace sobre un editor de texto sería editarlo con ese programa. Por lo tanto, lo que debería poder obtener es el "lugar" donde ha soltado el archivo para realizar la acción adecuada.
En principio me conformaría con saber si han soltado el "archivo" sobre una carpeta/escritorio para copiarlo allí.
__________________
Sonríe. Mañana puede ser peor.
Responder Con Cita
  #4  
Antiguo 30-12-2011
jplj jplj is offline
Miembro
 
Registrado: oct 2003
Posts: 189
Poder: 21
jplj Va por buen camino
He encontrado la solución en swissdelphicenter en concreto en este tip de R.Kleinpeter ...Drag and Drop files from your application to Windows Explorer?

Decir que a pesar del título no sólo las carpetas de windows aceptan los ficheros que se arrastran, también he comprobado que lo hace Paint y el Bloc de notas.

Tan sólo he tenido que modificar el tipo de Effect a LongInt en el procedimiento FileListBox1MouseMove.

Código Delphi [-]
procedure TForm1.FileListBox1MouseMove(Sender: TObject; Shift:
  TShiftState;
  X, Y: Integer);
const
  Threshold = 5;
var
  SelFileList: TStrings;
  i: Integer;
  DataObject: IDataObject;
//  Effect: DWORD;
  Effect: LongInt;
begin
Nota: Trabajo con Wndows XP y Delphi 7.


Por último dejo a continuación el código completo:
Código Delphi [-]
...Drag and Drop files from your application to Windows Explorer?
Author: R.Kleinpeter

Category: Files

{This example will show you how your application
will be able to copy files from your application to
Windows Explorer using Drag'n Drop.
Exactly the way it is done by the OS itself!

Create a new application containing just one unit,
called 'Unit1'. Drop a FileListBox and a DirectoryListBox on to the form,
leave their names the way they are.
Connect FileListBox1 with DirectoryListBox1 by setting the FileList-property of
DirectoryListBox1. Make sure that the MultiSelect-property of FileListBox1 is set to 'True'!

The best thing you can do now is to replace all text with the code below:}

//---------------------------------------------

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs,
  StdCtrls, FileCtrl, ActiveX, ShlObj, ComObj;

type
  TForm1 = class(TForm, IDropSource)
    FileListBox1: TFileListBox;
    DirectoryListBox1: TDirectoryListBox;
    procedure FileListBox1MouseDown(Sender: TObject; Button:
      TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure FileListBox1MouseMove(Sender: TObject; Shift: TShiftState;
      X,
      Y: Integer);
  private
    FDragStartPos: TPoint;
    function QueryContinueDrag(fEscapePressed: BOOL;
      grfKeyState: Longint): HResult; stdcall;
    function GiveFeedback(dwEffect: Longint): HResult; stdcall;
  public
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

function GetFileListDataObject(const Directory: string; Files:
  TStrings):
  IDataObject;
type
  PArrayOfPItemIDList = ^TArrayOfPItemIDList;
  TArrayOfPItemIDList = array[0..0] of PItemIDList;
var
  Malloc: IMalloc;
  Root: IShellFolder;
  FolderPidl: PItemIDList;
  Folder: IShellFolder;
  p: PArrayOfPItemIDList;
  chEaten: ULONG;
  dwAttributes: ULONG;
  FileCount: Integer;
  i: Integer;
begin
  Result := nil;
  if Files.Count = 0 then
    Exit;
  OleCheck(SHGetMalloc(Malloc));
  OleCheck(SHGetDesktopFolder(Root));
  OleCheck(Root.ParseDisplayName(0, nil,
    PWideChar(WideString(Directory)),
    chEaten, FolderPidl, dwAttributes));
  try
    OleCheck(Root.BindToObject(FolderPidl, nil, IShellFolder,
      Pointer(Folder)));
    FileCount := Files.Count;
    p := AllocMem(SizeOf(PItemIDList) * FileCount);
    try
      for i := 0 to FileCount - 1 do
      begin
        OleCheck(Folder.ParseDisplayName(0, nil,
          PWideChar(WideString(Files[i])), chEaten, p^[i],
          dwAttributes));
      end;
      OleCheck(Folder.GetUIObjectOf(0, FileCount, p^[0], IDataObject,
        nil,
        Pointer(Result)));
    finally
      for i := 0 to FileCount - 1 do begin
        if p^[i] <> nil then Malloc.Free(p^[i]);
      end;
      FreeMem(p);
    end;
  finally
    Malloc.Free(FolderPidl);
  end;
end;

function TForm1.QueryContinueDrag(fEscapePressed: BOOL;
  grfKeyState: Longint): HResult; stdcall;
begin
  if fEscapePressed or (grfKeyState and MK_RBUTTON = MK_RBUTTON) then
  begin
    Result := DRAGDROP_S_CANCEL
  end else if grfKeyState and MK_LBUTTON = 0 then
  begin
    Result := DRAGDROP_S_DROP
  end else
  begin
    Result := S_OK;
  end;
end;

function TForm1.GiveFeedback(dwEffect: Longint): HResult; stdcall;
begin
  Result := DRAGDROP_S_USEDEFAULTCURSORS;
end;

procedure TForm1.FileListBox1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if Button = mbLeft then
  begin
    FDragStartPos.x := X;
    FDragStartPos.y := Y;
  end;
end;

procedure TForm1.FileListBox1MouseMove(Sender: TObject; Shift:
  TShiftState;
  X, Y: Integer);
const
  Threshold = 5;
var
  SelFileList: TStrings;
  i: Integer;
  DataObject: IDataObject;
  Effect: DWORD;
begin
  with Sender as TFileListBox do
  begin
    if (SelCount > 0) and (csLButtonDown in ControlState)
      and ((Abs(X - FDragStartPos.x) >= Threshold)
      or (Abs(Y - FDragStartPos.y) >= Threshold)) then
      begin
      Perform(WM_LBUTTONUP, 0, MakeLong(X, Y));
      SelFileList := TStringList.Create;
      try
        SelFileList.Capacity := SelCount;
        for i := 0 to Items.Count - 1 do
          if Selected[i] then SelFileList.Add(Items[i]);
        DataObject := GetFileListDataObject(Directory, SelFileList);
      finally
        SelFileList.Free;
      end;
      Effect := DROPEFFECT_NONE;
      DoDragDrop(DataObject, Self, DROPEFFECT_COPY, Effect);
    end;
  end;
end;

initialization
  OleInitialize(nil);
finalization
  OleUninitialize;
end.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
{
As you might have seen, TForm1 is not only a member of class TForm,
but also of class IDropSource!

Now make sure that the two FileListBox events
'OnMouseMove' and 'OnMouseDown' are set correctly.

Run your application and try out the Drag and Drop feature!
You can select multiple items to drag and press escape to cancel.
The cursor will show you what action will take place.
}
__________________
Sonríe. Mañana puede ser peor.
Responder Con Cita
  #5  
Antiguo 02-01-2012
jplj jplj is offline
Miembro
 
Registrado: oct 2003
Posts: 189
Poder: 21
jplj Va por buen camino
Un "pequeño" detalle a la hora realizar nuestra aplicación:

Código Delphi [-]
type
  TForm1 = class(TForm, IDropSource)

No olvidar incluir IDropSource en la definición de nuestro formulario.
__________________
Sonríe. Mañana puede ser peor.
Responder Con Cita
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
El programa se queda "colgado" mientras copia y luego "despierta" NeWsP OOP 5 10-03-2010 22:05:40
Necesito llamar a métodos de clases "hija" desde su clase "padre" Flecha OOP 17 20-04-2007 00:03:53
ComboBox - Pasar un "Key" presionado afuera como si fuera de allí amadis OOP 7 10-11-2006 14:29:48
Fast Report "Fuera de memoria" BECERRA Impresión 0 25-12-2005 12:40:29
"Curiosidad" fuera de Contexto DANFIR Conexión con bases de datos 1 23-12-2003 08:00:58


La franja horaria es GMT +2. Ahora son las 09:30:45.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi