Search code examples
drag-and-dropnsis

NSIS PageEx Drag And Drop


I am trying to install a certificate using NSIS. But I want to use Drag And Drop without finding the file It is also well documented as HandleFileDragDrop.dll in the NSIS Reference. I have verified that it works with basic test code. But I don't use Page , I use PageEx . Below is a simple sample of my code.

Also, I'm a huge beginner with less than a week of experience with NSIS.

NSIS Code

// Page Part
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_COMPONENTS

PageEx custom
       PageCallBacks creatorBasic leaveBasic
PageExEnd

!insertmacro MUI_LANGUAGE "Korean"


// Install Part 
Function .onInit
   InitPluginsDir
   !insertmacro MUI_INSTALLOPTIONS_EXTRACT "Certification.ini"

   IntOp $0 ${SF_SELECTED} | ${SF_RO}
   SectionSetFlags 0 $0
FunctionEnd

// Section Part 
Section "Certification" SEC0000
        SetOutPath "$INSTDIR"
        SectionIn 1
        
        Push $CERTIFICATION
        Call AddCertificateToStore
        Pop $0
        ${If} $0 != success
             MessageBox MB_OK "Certification Install Fail : $0"
        ${EndIf}
        SetOverwrite on
SectionEnd

// Page Create 
Function creatorBasic
    ${IF} ${SectionIsSelected} ${SEC0000}
        !insertmacro MUI_HEADER_TEXT "Cert install" "Please Select install certification."
        !insertmacro MUI_INSTALLOPTIONS_INITDIALOG "Certification.ini"
        
        // This is the code I use to use Drag And Drop.
        FindWindow $1 "#32770" "" $HWNDPARENT
        GetDlgItem $1 $1 0x3FB
        HandleFileDragDrop::Register $1 ""
        
        !insertmacro MUI_INSTALLOPTIONS_SHOW
        
    ${Else}
    ${EndIf}
    abort
FunctionEnd

// Page leave
Function leaveBasic
    !insertmacro MUI_INSTALLOPTIONS_READ $CERTIFICATION "Certification.ini" "Field 2" "State"

    ${IF} ${SectionIsSelected} ${SEC0001}
        StrCmp $CERTIFICATION "" 0 +2
            MessageBox MB_OK "Please Select Cert." IDOK abort

        IfFileExists $CERTIFICATION found
            MessageBox MB_OK "Not exist Cert." IDOK abort
                goto abort
            found:
                goto done
    ${Else}
    ${EndIf}

    goto done
    
    abort:
        Abort
    done:
FunctionEnd

Certification.ini

; Ini file generated by the HM NIS Edit IO designer.
[Settings]
NumFields=2

[Field 1]
Type=Label
Text=Please Select Install Certification
Left=20
Right=129
Top=14
Bottom=22

[Field 2]
Type=FileRequest
Left=20
Right=256
Top=28
Bottom=43
Text=Find
Filter=Certification|*.crt

If the code is written like this, Drag and Drop does not work properly. Please let me know if the location is wrong or if there is a problem with the code.


Solution

  • The plug-in does not care about Page vs PageEx. I suspect GetDlgItem $1 $1 0x3FB is giving you the wrong handle.

    !insertmacro MUI_INSTALLOPTIONS_INITDIALOG "Certification.ini"
    !insertmacro INSTALLOPTIONS_READ "$1" "Certification.ini" "Field 2" "HWND"
    HandleFileDragDrop::Register $1 ""
    !insertmacro MUI_INSTALLOPTIONS_SHOW