Search code examples
nsis

NSIS: Getting the index of a selected ListBox Item


I'm dynamically filling a Listbox created with ${NSD_CreateListBox}. In a function I'm able to get the selected text, but would it be possible to get an index of the selected item?

${NSD_LB_GetSelection} $hCtl_parallelInstall_Installed $0 is what returns the full text only?

Thank you very much


Solution

  • nsDialogs does not have a macro for every single message in the Windows UI control library so sometimes you have to get the information directly from MSDN but in this case, the macro exists in recent versions of NSIS but has not been documented yet. If you are using a older version you can add the macro yourself:

    !include nsDialogs.nsh
    !ifndef NSD_LB_GetSelectionIndex
    !define NSD_LB_GetSelectionIndex `!insertmacro __NSD_LB_GetSelectionIndex `
    !macro __NSD_LB_GetSelectionIndex CONTROL VAR
        SendMessage ${CONTROL} ${LB_GETCURSEL} 0 0 ${VAR}
    !macroend
    !endif
    
    ...
    
    ${NSD_LB_GetSelectionIndex} $hCtl_parallelInstall_Installed $0