Board index » delphi » OnDragOver event not working!

OnDragOver event not working!

Hi Folks,

Have a bit of a problem with OnDragOver - it doesn't respond when draging
something from the outside world (like a file name from explorer).
Everything is OK when I try to drag a control which is ON the forms, but
not for the things from the outside.

What am I missing here?

TIA

--
Yoav Ben-Yosef
Haifa, Israel
Also available at: [email protected]
                     or: [email protected]

 

Re:OnDragOver event not working!


In article <[email protected]>,
   "Yoav Ben-Yosef" <[email protected]> wrote:

Quote
>Have a bit of a problem with OnDragOver - it doesn't respond when draging
>something from the outside world (like a file name from explorer).
>Everything is OK when I try to drag a control which is ON the forms, but
>not for the things from the outside.
>What am I missing here?

Nothing from "the world outside" is part of your application - Windows
actually provides specialized messages for applications that want to
handle it.

You have to put something in your app to handle the WM_DROPFILES message.
Like:

  procedure WMDropFiles(var Msg: TMessage); message WM_DROPFILES;

Msg.wParam will give you a "handle" to the drop structure for Windows.
Then, tkae a gander at DragAcceptFiles, DragQueryFile and DragFinish.

I haven't done it myself, and it does require a bit of API knowledge,
but there are quite a few people who have, but if you have the knack
for other API stuff, go for it :)

  --=- Ritchie Annand

Re:OnDragOver event not working!


On 31 Mar 1997, Yoav Ben-Yosef wrote:

Quote
> Hi Folks,

> Have a bit of a problem with OnDragOver - it doesn't respond when draging
> something from the outside world (like a file name from explorer).
> Everything is OK when I try to drag a control which is ON the forms, but
> not for the things from the outside.

> What am I missing here?

        Nothing. It doesn't work. Delphi's support for drag&drop is
proprietary. Which is pretty stupid if you ask me. To communicate with
the outside world, you need to use IDropTarget and IDropSource (?)
DCOM objects (I think they are defined in OLE2 unit) or WM_DROPFILES
window message if only need to accept dropped files.

Alex.

Re:OnDragOver event not working!


Quote
Alexei Novikov wrote:

> On 31 Mar 1997, Yoav Ben-Yosef wrote:

> > Hi Folks,

> > Have a bit of a problem with OnDragOver - it doesn't respond when draging
> > something from the outside world (like a file name from explorer).
> > Everything is OK when I try to drag a control which is ON the forms, but
> > not for the things from the outside.

> > What am I missing here?

>         Nothing. It doesn't work. Delphi's support for drag&drop is
> proprietary. Which is pretty stupid if you ask me. To communicate with
> the outside world, you need to use IDropTarget and IDropSource (?)
> DCOM objects (I think they are defined in OLE2 unit) or WM_DROPFILES
> window message if only need to accept dropped files.

> Alex.

If you only want to accept dropped files the following code snipped
from an app of mine works. (I got most of it from an article on the web
someplace, I've forgot where.)

procedure TfrmMain.FormCreate(Sender: TObject);
begin
  DragAcceptFiles(frmMain.Handle, true);
  Application.OnMessage := AppMessage;
  DragAcceptFiles(Application.Handle, true);
end;

procedure TfrmMain.AppMessage(var Msg: Tmsg; var Handled: Boolean);
const
    BufferLength : word = 1023;
var
    DroppedFilename : string;
    pDroppedFilename : array [0..1023] of Char;
begin
  if Msg.Message = WM_DROPFILES then
  begin
    DragQueryFile(Msg.WParam, 0, pDroppedFilename, BufferLength);
    DroppedFilename := StrPas(pDroppedFilename);
    OpenFile(DroppedFileName);
    DragFinish(Msg.WParam);
    Handled := true;
  end;
end;

Note that I am only interested in the first file dropped. Search the web
for the original code that handled multiple files.

FWIW,

     _/_/_/_/_/_/_/_/_/
    _/  _/_/       _/
   _/_/_/_/_/    _/
  _/    _/     _/
 _/    _/_/_/_/_/_/

Other Threads