Checkbox in NSIS -


i looking add basic checkbox default directory page using mui_page_customfunction_show in nsis. however, checkbox doesn't seem appearing or functioning in way. here different functions have attempted; i'm not sure if need grab current window in order draw it? advice appreciated.

!define mui_page_customfunction_show "directoryshow" !define mui_page_customfunction_leave "directoryleave" !insertmacro mui_page_directory  var checkbox  function directoryshow   ${nsd_createcheckbox} 0 0 50% 6% "checkboxtest"   pop $checkbox   ${nsd_check} $checkbox functionend  function directoryleave   ${nsd_getstate} $checkbox $0   ${if} $0 <> 0     messagebox mb_ok "checkbox checked."   ${endif} functionend 

nsd_create* supported on nsdialog pages (welcome , finish mui pages) not on internal nsis page directory.

to create control on internal pages must manually call createwindowex windows api function. of other nsd helper macros can still used on these controls:

!include mui2.nsh !include nsdialogs.nsh !define mui_page_customfunction_show "directoryshow" !define mui_page_customfunction_leave "directoryleave" !insertmacro mui_page_directory !insertmacro mui_page_components !insertmacro mui_page_instfiles !insertmacro mui_language english  var checkbox var checkstate ; stored globally remember choice if user presses button , goes our page !define checkheight 28  !ifmacrondef _z=  !error "nsis 2.51 or 3.0rc1 or later required!" !endif !macro createnativecontrol hparent cls style exstyle x y w h text ; note: supports pixel coordinates system::call 'user32::createwindowex(i ${exstyle}, t "${cls}", ts, ${style}, ${x}, ${y}, ${w}, ${h}, p ${hparent}, i0, i0, i0)p.s' "${text}" !macroend  function directoryshow   ; create space reducing height of top text:   system::call *(i,i,i,i)p.r0 ; nsis 2.51+   system::call 'user32::getwindowrect(p$mui.directorypage.text, pr0)'   system::call 'user32::mapwindowpoints(i0,p$mui.directorypage,p$0,i2)'   system::call '*$0(i.r2,i.r3,i.r4,i.r5)'   system::free $0   intop $5 $5 - ${checkheight}   system::call 'user32::setwindowpos(i$mui.directorypage.text,i,i,i,i$4,i$5,i0x6)'    ; create , initialize checkbox   intop $5 $3 + $5 ; y = texttop + textheight   !insertmacro createnativecontrol $mui.directorypage ${__nsd_checkbox_class} "${__nsd_checkbox_style}" "${__nsd_checkbox_exstyle}" 0 $5 300 ${checkheight} "checkboxtest"   pop $checkbox   sendmessage $mui.directorypage ${wm_getfont} 0 0 $0 ; dialog font   sendmessage $checkbox ${wm_setfont} $0 1 ; , apply new control   system::call 'user32::setwindowpos(i$checkbox,i0,i,i,i,i,i0x33)' ; make sure on top of tab order   ${ifthen} $checkstate == "" ${|} strcpy $checkstate 1 ${|} ; set default if our first time   ${nsd_setstate} $checkbox $checkstate functionend  function directoryleave   ${nsd_getstate} $checkbox $checkstate   ${if} $checkstate <> 0     messagebox mb_ok "checkbox checked."   ${endif} functionend 

alternatively, instead of creating control @ run-time can modify actual page (...\nsis\contrib\uis\modern.exe) resource hacker , apply new ui file mui_ui (changeui)


Comments