Skip to content
⌘ NSIS Forum Archive

Drag & Drop File

9 posts

Kuppy#

Drag & Drop File

I have a question NSIS can use the drag and drop files {NSD_CreateText}?

!define APPNAME "Drag & Drop"
NAME "${APPNAME}"
OutFile "${APPNAME}.exe"
InstallDir $temp
ShowInstDetails show
RequestExecutionLevel user
CompletedText "Drop files on me..."
DirText "You can drop a folder on the text field!"
SpaceTexts none
!include "MUI.nsh"
!include "WinCore.nsh"
!include "nsDialogs.nsh"
!include "LogicLib.nsh"
!include "WinMessages.nsh"
Page Custom "PageShow"
Page InstFiles
!insertmacro MUI_LANGUAGE 'English' 
var LabelText
Function "PageShow"
  FindWindow $1 "#32770" "" $HWNDPARENT
  GetDlgItem $0 $1 0x3E9
  EnableWindow $0 0
  GetDlgItem $0 $1 0x3FB
  HandleFileDragDrop::MakeDropWindow $0 ""
  nsDialogs::Create 1044
  Pop $0
  ${If} $0 == error
    Abort
  ${EndIf}
  ${NSD_CreateText} 0% 0% 100% 95% "$\r$\n$\r$\n$\r$\n$\r$\nDrag & Drop$\r$\n$\r$\n$\r$\n$\r$\nYour file here"
  Pop $LabelText
  ${NSD_Onchange} $LabelText "InstPageDrop"
  GetFunctionAddress $0 "InstPageDrop"
  HandleFileDragDrop::MakeDropWindow $HWNDPARENT $0
  nsDialogs::Show
FunctionEnd
Function "InstPageDrop"
  DetailPrint Drop:$0
   SendMessage $LabelText ${WM_SETTEXT} 0 'STR:$0'
  StrCpy $0 ""
FunctionEnd
Section
SectionEnd
Function .OnGuiEnd
  HandleFileDragDrop::NOP
FunctionEnd 
T.Slappy#
I would like to try this plugin, but Unicode version.

@Anders: are sources available? Can you upload them to wiki?
Anders#
I might have it on a old machine but this is a very simple plug-in, it would be easy to write from scratch.
Anders#
...and to answer the original question; yes, you can detect drops on any control. The first parameter you pass to the plug-in in the handle of the window/control.
nickdollahz#
Is it possible for the values to be returned in Natural Order(Windows Sort Order)?
Not sure how trivial that would be. If not maybe a nsis function or plugin that can?
Anders#
Why? And what is their natural order? The current sort mode in Explorer?

I believe they are returned in the order you select them, with the anchor first IIRC. Regardless, the plug-in just returns them in the order they are in the HDROP object.
nickdollahz#
The way Explorer sorts items by name:
1.txt
2.txt
10.txt

instead of
1.txt
10.txt
2.txt

Looks like it is returning in the order selected(which is natural order in my case). It just depends on the anchor you use as it will start with the anchor and return items from that point till the end then start from the beginning until that point. Which is actually how it works with most applications so I wont worry about it.

So if you have:
1.txt
2.txt
3.txt
4.txt
5.txt

and you highlight them all and then drag from 3.txt into the window. It will return:

3.txt
4.txt
5.txt
1.txt
2.txt


Thanks for your hard work. Unicode version has been clutch for the project I'm working on.
Anders#
If you are putting them in a ListBox or ListView then it is probably possible to sort them like Explorer with the system plug-in. At least the ListView has a sort callback message, not sure about the ListBox...