Drag and Drop

01/06/2010 - 02:19 por MABSoft | Informe spam
Hola
¿Como puedo hacer drag and Drop de un archivo hacia afuera de mi aplicación?

Tengo un ListView con el nombre completo del archivo en una de sus filas ,
quiero arrastrar ese nombre y que el archivo se copie donde suelto el mouse
(en el escritorio por ejemplo)
¿Se puede hacer esto?
Se como hacerlo hacia dentro de la aplicación, pero no tengo idea de como va
hacia afuera.
Desde ya muchas gracias a todos

Preguntas similare

Leer las respuestas

#1 langosta
01/06/2010 - 06:44 | Informe spam
"MABSoft" escribió en el mensaje de
noticias news:
Hola
¿Como puedo hacer drag and Drop de un archivo hacia afuera de mi
aplicación?

Tengo un ListView con el nombre completo del archivo en una de sus
filas , quiero arrastrar ese nombre y que el archivo se copie donde
suelto el mouse (en el escritorio por ejemplo)
¿Se puede hacer esto?



Si, por qué no...

Se como hacerlo hacia dentro de la aplicación, pero no tengo idea de
como va hacia afuera.



La función que debes incovar se llama DoDragDrop() y requiere como
parámetros la implementación de dos "interfaces": IDropSource e
IDataObject.

Cuando el drop se hace efectivo, empaquetas un objeto de tipo HDROP o
sea el handle que te devuelve GlobalAlloc() en el que copias la data en
formato CF_DROP

La data consta de una cabecera de tipo DROPFILES y a continuación la
lista de el o los archivos en la forma de strings terminados en NUL y un
string vacío como terminador (o sea, un doble NUL final)

"x:\pepe.doc" & chr(0) & chr(0)

Hay otros formatos posibles

CFSTR_FILECONTENTS
CFSTR_FILEDESCRIPTOR
CFSTR_FILENAME
CFSTR_FILENAMEMAP
CFSTR_MOUNTEDVOLUME
CFSTR_SHELLIDLIST
CFSTR_SHELLIDLISTOFFSET

casi todos, sino todos, empaquetados en un hglobal.

Desde ya muchas gracias a todos
Respuesta Responder a este mensaje
#2 MABSoft
02/06/2010 - 02:29 | Informe spam
Hola Langosta, Gracias por contestar
DoDragDrop() no es una función de la API ¿O sí?, no la encuentro...
Si hay algo ya implementado con esta función ¿de donde lo puedo sacar?

Estoy usando VB6 SP6

De nuevo Muchas Gracias

"langosta" escribió en el mensaje
news:hu2378$vpf$
"MABSoft" escribió en el mensaje de
noticias news:
Hola
¿Como puedo hacer drag and Drop de un archivo hacia afuera de mi
aplicación?

Tengo un ListView con el nombre completo del archivo en una de sus filas
, quiero arrastrar ese nombre y que el archivo se copie donde suelto el
mouse (en el escritorio por ejemplo)
¿Se puede hacer esto?



Si, por qué no...

Se como hacerlo hacia dentro de la aplicación, pero no tengo idea de como
va hacia afuera.



La función que debes incovar se llama DoDragDrop() y requiere como
parámetros la implementación de dos "interfaces": IDropSource e
IDataObject.

Cuando el drop se hace efectivo, empaquetas un objeto de tipo HDROP o sea
el handle que te devuelve GlobalAlloc() en el que copias la data en
formato CF_DROP

La data consta de una cabecera de tipo DROPFILES y a continuación la lista
de el o los archivos en la forma de strings terminados en NUL y un string
vacío como terminador (o sea, un doble NUL final)

"x:\pepe.doc" & chr(0) & chr(0)

Hay otros formatos posibles

CFSTR_FILECONTENTS
CFSTR_FILEDESCRIPTOR
CFSTR_FILENAME
CFSTR_FILENAMEMAP
CFSTR_MOUNTEDVOLUME
CFSTR_SHELLIDLIST
CFSTR_SHELLIDLISTOFFSET

casi todos, sino todos, empaquetados en un hglobal.

Desde ya muchas gracias a todos



Respuesta Responder a este mensaje
#3 langosta
02/06/2010 - 03:11 | Informe spam
"MABSoft" escribió en el mensaje de
noticias news:
Hola Langosta, Gracias por contestar
DoDragDrop() no es una función de la API ¿O sí?, no la encuentro...
Si hay algo ya implementado con esta función ¿de donde lo puedo sacar?

Estoy usando VB6 SP6




Sí. Es una función de ole32.dll (al final te pego la doc del sdk)

Vos llamás a esta función cuando el listview te notifica que el drag ha
comenzado.

La implementación de IDropSource es bastante trivial, un par de métodos
y un par de líneas de código para cada uno.

IDataObject es un poco más complicado, pero está bien documentado y
quizá encuentres ejemplos. Cuando el ratón entre en alguna ventana qu
acepte drop, tu implementación de la interface deberá responder qué
formato de data ofrece (en tu caso CF_DROP) y de que manera (un hgobal).
Y, en caso de que se produzca el drop, la implementación debe armar y
empaquetar la data para que la función se la entregue al target.

Si yo no recuerdo mal, Eduardo Morcillo había compilado una referencia
(un archivo tlb), conteniendo la descripción de estas interfaces que
seguramente vas a necesitar para implementaras desde vb.


Carries out an OLE drag and drop operation.

WINOLEAPI DoDragDrop(
IDataObject * pDataObject, //Pointer to the data object
IDropSource * pDropSource, //Pointer to the source
DWORD dwOKEffect, //Effects allowed by the source
DWORD * pdwEffect //Pointer to effects on the source
);


Parameters
pDataObject
[in] Pointer to the IDataObject interface on a data object that contains
the data being dragged.

pDropSource
[in] Pointer to an implementation of the IDropSource interface, which is
used to communicate with the source during the drag operation.

dwOKEffect
[in] Effects the source allows in the OLE drag-and-drop operation. Most
significant is whether it permits a move. The dwOKEffect and pdwEffect
parameters obtain values from the DROPEFFECT enumeration. For a list of
values, see DROPEFFECT.

pdwEffect
[out] Pointer to a value that indicates how the OLE drag-and-drop
operation affected the source data. The pdwEffect parameter is set only
if the operation is not canceled.

Return Values
This function supports the standard return value E_OUTOFMEMORY, as well
as the following:

DRAGDROP_S_DROP
The OLE drag-and-drop operation was successful.

DRAGDROP_S_CANCEL
The OLE drag-and-drop operation was canceled.

E_UNSPEC
Unexpected error occurred.

Remarks
Note:
You must call OleInitialize before calling this function.

If you are developing an application that can act as a data source for
an OLE drag-and-drop operation, you must call DoDragDrop when you detect
that the user has started an OLE drag-and-drop operation.

The DoDragDrop function enters a loop in which it calls various methods
in the IDropSource and IDropTarget interfaces. (For a successful
drag-and-drop operation, the application acting as the data source must
also implement IDropSource, while the target application must implement
IDropTarget.)

The DoDragDrop function determines the window under the current cursor
location. It then checks to see if this window is a valid drop target.

If the window is a valid drop target, DoDragDrop calls
IDropTarget::DragEnter. This method supplies an effect code indicating
what would happen if the drop actually occurred. For a list of valid
drop effects, see the DROPEFFECT enumeration.

DoDragDrop calls IDropSource::GiveFeedback with the effect code so that
the drop source interface can provide appropriate visual feedback to the
user. The pDropSource pointer passed into DoDragDrop specifies the
appropriate IDropSource interface.

DoDragDrop tracks mouse cursor movements and changes in the keyboard or
mouse button state.

If the user moves out of a window, DoDragDrop calls
IDropTarget::DragLeave.

If the mouse enters another window, DoDragDrop determines if that window
is a valid drop target and then calls IDropTarget::DragEnter for that
window.

If the mouse moves but stays within the same window, DoDragDrop calls
IDropTarget::DragOver.

If there is a change in the keyboard or mouse button state, DoDragDrop
calls IDropSource::QueryContinueDrag and determines whether to continue
the drag, to drop the data, or to cancel the operation based on the
return value.

If the return value is S_OK, DoDragDrop first calls
IDropTarget::DragOver to continue the operation. This method returns a
new effect value and DoDragDrop then calls IDropSource::GiveFeedback
with the new effect so appropriate visual feedback can be set. For a
list of valid drop effects, see the DROPEFFECT enumeration.
IDropTarget::DragOver and IDropSource::GiveFeedback are paired so that
as the mouse moves across the drop target, the user is given the most
up-to-date feedback on the mouse's position.

If the return value is DRAGDROP_S_DROP, DoDragDrop calls
IDropTarget::Drop. The DoDragDrop function returns the last effect code
to the source, so the source application can perform the appropriate
operation on the source data, for example, cut the data if the operation
was a move.

If the return value is DRAGDROP_S_CANCEL, the DoDragDrop function calls
IDropTarget::DragLeave.

Requirements
For an explanation of the requirement values, see Requirements (COM).

Windows NT/2000/XP: Requires Windows NT 3.1 or later.

Windows 95/98: Requires Windows 95 or later.

Header: Declared in ole2.h.

Import Library: Use ole32.lib.

See Also
Reference
IDropSource
Respuesta Responder a este mensaje
#4 MABSoft
02/06/2010 - 03:29 | Informe spam
De nuevo muchas gracias "Maestro"
Voy a tratar, luego comento...

"langosta" escribió en el mensaje
news:hu4b4a$ep5$
"MABSoft" escribió en el mensaje de
noticias news:
Hola Langosta, Gracias por contestar
DoDragDrop() no es una función de la API ¿O sí?, no la encuentro...
Si hay algo ya implementado con esta función ¿de donde lo puedo sacar?

Estoy usando VB6 SP6




Sí. Es una función de ole32.dll (al final te pego la doc del sdk)

Vos llamás a esta función cuando el listview te notifica que el drag ha
comenzado.

La implementación de IDropSource es bastante trivial, un par de métodos y
un par de líneas de código para cada uno.

IDataObject es un poco más complicado, pero está bien documentado y quizá
encuentres ejemplos. Cuando el ratón entre en alguna ventana qu acepte
drop, tu implementación de la interface deberá responder qué formato de
data ofrece (en tu caso CF_DROP) y de que manera (un hgobal). Y, en caso
de que se produzca el drop, la implementación debe armar y empaquetar la
data para que la función se la entregue al target.

Si yo no recuerdo mal, Eduardo Morcillo había compilado una referencia (un
archivo tlb), conteniendo la descripción de estas interfaces que
seguramente vas a necesitar para implementaras desde vb.


> Carries out an OLE drag and drop operation.

WINOLEAPI DoDragDrop(
IDataObject * pDataObject, //Pointer to the data object
IDropSource * pDropSource, //Pointer to the source
DWORD dwOKEffect, //Effects allowed by the source
DWORD * pdwEffect //Pointer to effects on the source
);


Parameters
pDataObject
[in] Pointer to the IDataObject interface on a data object that contains
the data being dragged.

pDropSource
[in] Pointer to an implementation of the IDropSource interface, which is
used to communicate with the source during the drag operation.

dwOKEffect
[in] Effects the source allows in the OLE drag-and-drop operation. Most
significant is whether it permits a move. The dwOKEffect and pdwEffect
parameters obtain values from the DROPEFFECT enumeration. For a list of
values, see DROPEFFECT.

pdwEffect
[out] Pointer to a value that indicates how the OLE drag-and-drop
operation affected the source data. The pdwEffect parameter is set only if
the operation is not canceled.

Return Values
This function supports the standard return value E_OUTOFMEMORY, as well as
the following:

DRAGDROP_S_DROP
The OLE drag-and-drop operation was successful.

DRAGDROP_S_CANCEL
The OLE drag-and-drop operation was canceled.

E_UNSPEC
Unexpected error occurred.

Remarks
Note:
You must call OleInitialize before calling this function.

If you are developing an application that can act as a data source for an
OLE drag-and-drop operation, you must call DoDragDrop when you detect that
the user has started an OLE drag-and-drop operation.

The DoDragDrop function enters a loop in which it calls various methods in
the IDropSource and IDropTarget interfaces. (For a successful
drag-and-drop operation, the application acting as the data source must
also implement IDropSource, while the target application must implement
IDropTarget.)

The DoDragDrop function determines the window under the current cursor
location. It then checks to see if this window is a valid drop target.

If the window is a valid drop target, DoDragDrop calls
IDropTarget::DragEnter. This method supplies an effect code indicating
what would happen if the drop actually occurred. For a list of valid drop
effects, see the DROPEFFECT enumeration.

DoDragDrop calls IDropSource::GiveFeedback with the effect code so that
the drop source interface can provide appropriate visual feedback to the
user. The pDropSource pointer passed into DoDragDrop specifies the
appropriate IDropSource interface.

DoDragDrop tracks mouse cursor movements and changes in the keyboard or
mouse button state.

If the user moves out of a window, DoDragDrop calls
IDropTarget::DragLeave.

If the mouse enters another window, DoDragDrop determines if that window
is a valid drop target and then calls IDropTarget::DragEnter for that
window.

If the mouse moves but stays within the same window, DoDragDrop calls
IDropTarget::DragOver.

If there is a change in the keyboard or mouse button state, DoDragDrop
calls IDropSource::QueryContinueDrag and determines whether to continue
the drag, to drop the data, or to cancel the operation based on the return
value.

If the return value is S_OK, DoDragDrop first calls IDropTarget::DragOver
to continue the operation. This method returns a new effect value and
DoDragDrop then calls IDropSource::GiveFeedback with the new effect so
appropriate visual feedback can be set. For a list of valid drop effects,
see the DROPEFFECT enumeration. IDropTarget::DragOver and
IDropSource::GiveFeedback are paired so that as the mouse moves across the
drop target, the user is given the most up-to-date feedback on the mouse's
position.

If the return value is DRAGDROP_S_DROP, DoDragDrop calls
IDropTarget::Drop. The DoDragDrop function returns the last effect code to
the source, so the source application can perform the appropriate
operation on the source data, for example, cut the data if the operation
was a move.

If the return value is DRAGDROP_S_CANCEL, the DoDragDrop function calls
IDropTarget::DragLeave.

Requirements
For an explanation of the requirement values, see Requirements (COM).

Windows NT/2000/XP: Requires Windows NT 3.1 or later.

Windows 95/98: Requires Windows 95 or later.

Header: Declared in ole2.h.

Import Library: Use ole32.lib.

See Also
Reference
IDropSource

Respuesta Responder a este mensaje
#5 langosta
02/06/2010 - 03:45 | Informe spam
"MABSoft" escribió en el mensaje de
noticias news:%
De nuevo muchas gracias "Maestro"
Voy a tratar, luego comento...




Ok. No fue mi intención tanta palabrería y tan poca ayuda. Vos sabés
como es esto de "la red" y de "san google", ni bien te alejas un pasito
de la orilla, los ejemplos desaparecen.

Aunque... yo estoy casi seguro que hay ejemplos completo de
implementación de ambas interfaces y de la función en el sdk de windows.
Pero en C/C++.
Respuesta Responder a este mensaje
Ads by Google
Help Hacer una preguntaSiguiente Respuesta Tengo una respuesta
Search Busqueda sugerida