Search code examples
nsis

How to show the print dilaog to select the option to print when clicked on "print" from the license agreement installer screen using NSIS


How to show the print dialog to select the option to print when clicked on "print" from the license agreement installer screen using NSIS.

I want to display the below screen when clicked on "Print" from the License agreement screen.

If i use the below command it is directly printing the page without popping up the Print dialog.


Solution

  • There is no built-in support but you can display this common dialog with the system plug-in:

    !include LogicLib.nsh
    !define /IfNDef PD_HIDEPRINTTOFILE 0x00100000
    !define /IfNDef PD_NOSELECTION 0x00000004
    !define /IFNDef PD_USEDEVMODECOPIESANDCOLLATE 0x00040000 ; Just one copy
    
    
    Function ShowPrintDlg
    System::Call '*(p0,p$hwndparent,p0,p0,p,i${PD_HIDEPRINTTOFILE}|${PD_NOSELECTION}|${PD_USEDEVMODECOPIESANDCOLLATE},&i2,&i2,&i2,&i2,&i2,p,p,p,p,p0,p0,p0,p0,&l.r0)p.r1'
    System::Call '*$1(ir0)'
    System::Call 'COMDLG32::PrintDlg(pr1)i.r0'
    ${If} $0 <> 0
        System::Call '*$1(p,p,p.r3,p.r4,t""r2)'
        System::Free $1
        System::Call 'KERNEL32::GlobalFree(pr3)'
        System::Call 'KERNEL32::GlobalLock(pr4)p.r1'
        ${If} $1 P<> 0
            System::Call '*$1(&i2,&i2.r2,&i2,&i2)'
            System::Call '*$1(&i$2,&t999.r2)'
            System::Call 'KERNEL32::GlobalUnlock(pr1)'
            System::Call 'KERNEL32::GlobalFree(pr4)'
        ${EndIf}
        MessageBox mb_ok 'User wants to print to "$2"'
    ${Else}
        System::Free $1
    ${EndIf}
    FunctionEnd
    
    Page InstFiles
    
    Section
    Call ShowPrintDlg
    SectionEnd