Recent

Author Topic: How do I know when a file is being dragged into my main window?  (Read 724 times)

lugdanum

  • New Member
  • *
  • Posts: 14
Bonjour

Comment savoir quand un fichier est en train d'être glissé dans ma fenêtre principale ?

J'aimerais pouvoir changer l'image de fond (par exemple) de ma fênetre lorsqu'un utilisateur passe dessus avec un fichier en mode glisser/déposer.

En gros comment savoir que la personne est en train de glisser un fichier sur ma fenêtre et donc agir avant le déposer ?

Merci beaucoup d'avance.

- - - - - - 
Hello

How do I know when a file is being dragged into my main window?

I would like to be able to change the background image (for example) of my window when a user passes over it with a file in drag and drop mode.

Basically how to know that the person is dragging a file on my window and therefore act before depositing it?

Thank you very much in advance.

RAW

  • Hero Member
  • *****
  • Posts: 867
Re: How do I know when a file is being dragged into my main window?
« Reply #1 on: June 04, 2020, 12:14:11 am »
Maybe like this ...  :)

AllowDropFiles:= True;
Code: Pascal  [Select][+][-]
  1. Procedure TForm1.FormDropFiles(Sender:TObject;Const FileNames:Array Of String);
  2. Var
  3.  i:Integer;
  4.  strExt:String;
  5. Begin
  6.   // check file suffix
  7.   For i:= Low(FileNames) To High(FileNames)
  8.   Do
  9.    Begin
  10.     strExt:= LowerCase(ExtractFileExt(FileNames[i]));
  11.     If ((strExt = '.txt') Or (strExt = '.log') Or (strExt = '.ini'))
  12.     Then Color:= clBlue;
  13.    End;
  14. End;
Windows 7 Pro (x64 Sp1) And Windows XP Pro (x86 Sp3) - LAZARUS 2.0.8 FPC 3.0.4 - TRUNK 2.1.0 FPC 3.3.1
// This is polarity (hell) and hell is reigned by lies, nothing but lies. Be careful what you believe ...
// There are 10 types of people in this world, those who understand mind control and ...

lugdanum

  • New Member
  • *
  • Posts: 14
Re: How do I know when a file is being dragged into my main window?
« Reply #2 on: June 04, 2020, 11:11:37 am »
Hello

Thank you very much, but in fact I did not explain myself well.
I would like to get the same thing as on this example:
https://i0.wp.com/css-tricks.com/wp-content/uploads/2015/11/drag-drop-upload-1.gif?ssl=1

ie detect when the user arrives with a file in drag and drop on my window to change the background image for example, act before he drops the file.

thank you so much

-----------------------------

Bonjour

Merci beaucoup, mais en fait je me suis mal expliqué.
J'aimerais obtenir la même chose que sur cet exemple :
https://i0.wp.com/css-tricks.com/wp-content/uploads/2015/11/drag-drop-upload-1.gif?ssl=1

c'est à dire détecter quand l'utilisateur arrive avec un fichier en drag and drop sur ma fenêtre pour changer l'image de fond par exemple, agir avant qu'il dépose/lâche le fichier.

Merci beaucoup

RAW

  • Hero Member
  • *****
  • Posts: 867
Re: How do I know when a file is being dragged into my main window?
« Reply #3 on: June 04, 2020, 05:04:49 pm »
Yes, I overlooked two things: "LINUX" and "act before depositing it" ...  :)
I guess you need to take a look at the LINUX-Api for that ... On Windows it's always the same thing: If you need something special then the OS-Api is your best friend...

A solution might be:
1. Set AllowDropFiles:= True (FORM, WND)
2. React on the changed cursor icon (LMessages: CM_CURSORCHANGED)

Maybe that's a starting point ...
« Last Edit: June 04, 2020, 06:44:29 pm by RAW »
Windows 7 Pro (x64 Sp1) And Windows XP Pro (x86 Sp3) - LAZARUS 2.0.8 FPC 3.0.4 - TRUNK 2.1.0 FPC 3.3.1
// This is polarity (hell) and hell is reigned by lies, nothing but lies. Be careful what you believe ...
// There are 10 types of people in this world, those who understand mind control and ...

440bx

  • Hero Member
  • *****
  • Posts: 1938
Re: How do I know when a file is being dragged into my main window?
« Reply #4 on: June 04, 2020, 06:44:32 pm »
ie detect when the user arrives with a file in drag and drop on my window to change the background image for example, act before he drops the file.
Just so you know, that page is _not_ detecting that a file is being dragged onto it.  It's just a .gif that continuously changes regardless of whether a file is being dragged onto it or not.

Also, under Windows @RAW is correct.  Detecting the change in cursor icon is the first step to find out if something is being dragged onto the window.  In addition to that, it would be good to use GetCapture() to ensure the mouse is captured (drag & drop requires the mouse to be captured.) You can even find out which program/process the drag originated from by calling GetGUIThreadInfo.

HTH.

FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

lugdanum

  • New Member
  • *
  • Posts: 14
Re: How do I know when a file is being dragged into my main window?
« Reply #5 on: June 04, 2020, 07:02:49 pm »
Hello

A solution might be:
1. Set AllowDropFiles:= True (FORM, WND)
2. React on the changed cursor icon (LMessages: CM_CURSORCHANGED)

-> Thank you for this start of the track, I hadn't thought of looking there.
Merci pour ce début de piste je n'avais pas pensé à regarder par là.

Just so you know, that page is _not_ detecting that a file is being dragged onto it.  It's just a .gif that continuously changes regardless of whether a file is being dragged onto it or not.

-> Lol seriously  :D? it was just to show what i wanted to get, thanks i didn't know it was a gif ;D
Lol sérieux ? c'était juste pour montrer ce que je voulais obtenir, merci je ne savais pas que c'était un gif ;-)

Also, under Windows @RAW is correct.  Detecting the change in cursor icon is the first step to find out if something is being dragged onto the window.  In addition to that, it would be good to use GetCapture() to ensure the mouse is captured (drag & drop requires the mouse to be captured.) You can even find out which program/process the drag originated from by calling GetGUIThreadInfo.

-> In any case a big thank you too, I will see and look on this side, thank you!
En tout cas un grand merci aussi, je vais voir et chercher de ce côté, merci !

 :)

 

TinyPortal © 2005-2018