NSIS ListView - GetItemText返回错误的值

时间:2017-12-11 16:32:38

标签: windows listview nsis


我尝试使用ListView创建Windows安装程序。我可以将项目插入列表视图:

# put the plugin version to list view (in my case value 2.2)
${NSD_LV_InsertItem} $list $i '$5' 

但是当我尝试读取给定索引的值时:

# get selected item plugin version
${NSD_LV_GetItemText} $list 0 0 $R0
MessageBox MB_OK "The text of item 0 is: $R0"

我收到消息:项目0的文字是:▯2
为什么输出没有正确显示?

谢谢!

1 个答案:

答案 0 :(得分:0)

“▯2”是被视为UTF-16LE字符串的“2.2”ASCII字符串。

第三方CommCtrl.nsh文件有问题,您需要确保LVM_ *定义对您的目标是正确的。

!include nsDialogs.nsh
!include WinMessages.nsh ; The 3rd-party CommCtrl.nsh file is buggy, include this first to make sure LVM_* is defined correctly
!ifndef LVM_GETITEMTEXT
!define /math LVM_GETITEMTEXTA ${LVM_FIRST} + 45
!define /math LVM_GETITEMTEXTW ${LVM_FIRST} + 115
${_NSIS_DEFAW} LVM_GETITEMTEXT
!endif
!include "CommCtrl.nsh"
!define /ifndef _COMMCTRL_NSH_VERBOSE ${_COMMCTRL_VERBOSE}

Page Custom MyPage

Var /Global List
Var /Global i

Function MyPage
nsDialogs::Create 1018
Pop $0

${NSD_CreateListView} 0u 0u 300u 50% "Listview"
Pop $list
StrCpy $i 0
StrCpy $5 "2.2"
${NSD_LV_InsertColumn} $list 0 200 "column 0"
${NSD_LV_InsertItem} $list $i '$5' 

${NSD_CreateButton} 0 60% 100% 13u "MsgBox item 0"
Pop $0
${NSD_OnClick} $0 DisplayItem0

nsDialogs::Show
FunctionEnd

Function DisplayItem0
Pop $R0
${NSD_LV_GetItemText} $list 0 0 $R0
MessageBox MB_OK "The text of item 0 is: $R0"
FunctionEnd