Search code examples
nsis

Using NSIS, Custom Page Two Question. ListView / NSISList Text


Thank you :]

  1. When using ListView, Korean is not expressed, but strange characters are displayed. (Photo attached) And some characters are well included in List(NSISList), but some characters are not. I tried adding the source below, but the text didn't show up properly. What sources do I need to add to get the text to look right? I am using NSIS 3.x version.

    !ifndef LVM_GETITEMTEXT

    !define /math LVM_GETITEMTEXTA ${LVM_FIRST} + 45

    !define /math LVM_GETITEMTEXTW ${LVM_FIRST} + 115

    ${_NSIS_DEFAW} LVM_GETITEMTEXT

    !endif

enter image description here

  1. I will express it in Korean. It is used by adding any character to the List. Before adding, if it is displayed as a MessageBox, it comes out well, and the character is added to the List. But when I tried to add it and use it again, the characters were cut off, and even when I printed it to the TextBox, it didn't come out. Based on "대", the characters after it are not stored in the List.

ex) 서대문 = "서", 대구 = ""

Function ListTest
 ${List.Create} Aerch
 ${List.Add} Serch "서대문구"
 ${List.Get} $0 Serch 0
 
 MessageBox MB_OK $0
FunctionEnd
; Return $0 = 서

Solution

    • Make sure you have Unicode True at the start of your script.
    • Make sure you save your script as UTF-8 BOM or UTF-16LE BOM.
    • !include nsDialogs before commctrl.nsh
    • Make sure you are using the Unicode version of all plug-ins.

    Characters that "look Chinese" is a symptom of treating ASCII as UTF-16. Strings cut off after the first character is a symptom of treating UTF-16 as ASCII (not a Unicode plug-in?).

    This works for me:

    Unicode True
    RequestExecutionLevel user
    
    !include nsDialogs.nsh
    !define _COMMCTRL_NSH_VERBOSE 3
    !include commctrl.nsh
    
    Section
    SectionEnd
    Page custom nsDialogsPage
    Var lv
    
    
    Function msgboxtext
    Pop $0
    SendMessage $lv ${LVM_GETSELECTIONMARK} 0 0 $8
    StrCpy $9 1
    ${If} $8 = -1 
    Return
    ${EndIf}
    
    System::Call '*(&t${NSIS_MAX_STRLEN})p.r3'
    System::Call "*(i, i, i, i, i, p, i, i, i) p  (0, 0, $9, 0, 0, r3, ${NSIS_MAX_STRLEN}) .r1"
    System::Call "User32::SendMessage(p, i, p, p) p ($lv, ${LVM_GETITEMTEXT}, $8, r1)"
    System::Call "*$3(&t${NSIS_MAX_STRLEN} .r4)"
    System::Free $1
    System::Free $3
    MessageBox mb_ok $4
    FunctionEnd
    
    Function nsDialogsPage
    nsDialogs::Create 1018
    Pop $0
    
    ${NSD_CreateButton} 0 0 100% 12u "Get text"
    Pop $9
    ${NSD_OnClick} $9 msgboxtext
    
    nsDialogs::CreateControl /NOUNLOAD ${WC_LISTVIEW} ${__NSD_ListView_STYLE}|${WS_TABSTOP} ${__NSD_ListView_EXSTYLE}  0 13u 100% -13u ""
    Pop $lv
    ${NSD_LV_InsertColumn} $lv 0 100 "column 0"
    ${NSD_LV_InsertColumn} $lv 1 70 "서대문"
    
    ${NSD_LV_InsertItem} $lv 0 '서대문'
    ${NSD_LV_SetItemText} $lv 0 1 '서대문 서대문'
    
    ${NSD_LV_InsertItem} $lv 1 '2 서대문'
    ${NSD_LV_SetItemText} $lv 1 1 '2.2 서대문 서대문'
    
    
    nsDialogs::Show
    FunctionEnd