Archive: nsDialogs - Listbox with drive letters


nsDialogs - Listbox with drive letters
  Hey how to create Listbox with drive letters selection ?

i need it to use as variable for command ie. "something.exe $letter" (letter without :)


Use the GetDrives functionality from the FileFunc.nsh header file (comes with NSIS), and in the callback function you specify for it, add the drive letters/etc. to the dropdown list.

e.g.


!include "winmessages.nsh"
!include "LogicLib.nsh"
!include "nsDialogs.nsh"

!include "FileFunc.nsh"

Outfile "test.exe"

var dialog
var hwnd
var null

Page custom customPage

Function customPage
nsDialogs::Create 1018
Pop $dialog

${NSD_CreateDroplist} 0 0 100% 100% ""
Pop $hwnd
${NSD_OnChange} $hwnd db_select.onchange
${GetDrives} "ALL" driveListFiller

nsDialogs::Show
FunctionEnd
Function db_select.onchange
Pop $hwnd
${NSD_GetText} $hwnd $0
MessageBox MB_OK "Drive selected: $0"
FunctionEnd

Function driveListFiller
SendMessage $hwnd ${CB_ADDSTRING} 0 "STR:$9 [$8]"
Push 1 ; must push something - see GetDrives documentation
FunctionEnd

Section ""
SectionEnd

oh uhh... I created a Droplist, but you can easily retool it for a List %) just replace NSD_CreateDroplist with NSD_CreateListbox and CB_ADDSTRING with LB_ADDSTRING


If we select the line, the messagebox doesn't show selected item text. I have tried the code below, but there must be an easier way to do it:


onchange

Pop $hwnd

SendMessage $hwnd${LB_GETCURSEL} 0 0 $0
SendMessage $hwnd${LB_GETTEXTLEN} $0 0 $1

System
::alloc $1
Pop$2

SendMessage $hwnd${LB_GETTEXT} $0 $2
System::Call "*$2(&t1024 .r3)"
System::free $2

MessageBox MB_OK "Drive selected: $3"
>FunctionEnd
>

odd- seems to work for me:


!include "winmessages.nsh"
!include "LogicLib.nsh"
!include "nsDialogs.nsh"

!include "FileFunc.nsh"

Outfile "test.exe"

var dialog
var hwnd
var null

Page custom customPage

Function customPage
nsDialogs::Create 1018
Pop $dialog

${NSD_CreateListbox} 0 0 100% 100% ""
Pop $hwnd
${NSD_OnChange} $hwnd db_select.onchange
${GetDrives} "ALL" driveListFiller

nsDialogs::Show
FunctionEnd

Function db_select.onchange
Pop $hwnd

SendMessage $hwnd ${LB_GETCURSEL} 0 0 $0
SendMessage $hwnd ${LB_GETTEXTLEN} $0 0 $1

System::alloc $1
Pop $2

SendMessage $hwnd ${LB_GETTEXT} $0 $2
System::Call "*$2(&t1024 .r3)"
System::free $2

MessageBox MB_OK "Drive selected: $3"
FunctionEnd

Function driveListFiller
SendMessage $hwnd ${LB_ADDSTRING} 0 "STR:$9 [$8]"
Push 1
FunctionEnd

Section ""
SectionEnd


That said - yes, there's easier methods.. nsDialogs actually has good support for listboxes built-in;
http://nsis.sourceforge.net/Docs/nsD...ef-lbaddstring
http://nsis.sourceforge.net/Docs/nsD...lbgetselection

Sorry, it was a misunderstanding, the code worked for me too :)
I was trying to say that the code could be smaller.


not much smaller - short of abstracting it into a macro/function; which is what NSD_LB_GetSelection and such are