Archive: Updating Listbox


Updating Listbox
On a simple ini screen, i have 3 items: 1) FileRequest, 2) Listbox, and 3) Button.

I want the user to choose a file with the FileRequest, then click on the Button to add the filepath to the Listbox. (Ideally it would automatically add the filepath to the list when FileRequest is clicked, or by clicking on the button, a file dialog appears, thus making the FileRequest unncessary. But that can come later.)

I've set up the Button with a flag of NOTIFY so I can call a function which will read the data from the FileRequest object and add it to the ListItems of the listbox.

So the code for the function is like this:
---------
;Get filepath from the FileRequest [field #2]
!insertmacro MUI_INSTALLOPTIONS_READ $FROM_FILE_REQUEST "mysimplescreen.ini" "Field 2" "State"

;Get the current list from the ListBox [field #4]
!insertmacro MUI_INSTALLOPTIONS_READ $CURRENT_LIST "mysimplescreen.ini" "Field 4" ListItems

;Add the new item to list
StrCpy $NEW_LIST "$CURRENT_LIST|$FROM_FILE_REQUEST"

;replace the ListItems in the listbox
!insertmacro MUI_INSTALLOPTIONS_WRITE "mysimplescreen.ini" "Field 4" ListItems "$NEW_LIST"

------------

Please pardon me if this is wrong way of doing what I want. I've just been using nsi for a few days... Anyhow, the problem is - although I can tell that the ListItems has actually changed (with the help of MessageBox), the screen doesn't actually show the changed list. I searched on this forum and someone mentioned "SendMessage"? I've looked at the documentation for that but am uncertain how to use it.

Am I basically missing a step to REFRESH the screen, and SendMessage is one way to do that? Any help you can provide would be wonderful, thanks in advance!

-paul


No takers? :(


1. Modern UI custom page
2. FileRequest control (autoadd in ListBox or not)
3. Add file to ListBox button
4. Delete file from ListBox button
5. You must select file to enable Next button
6. If file already exists in ListBox then shows message
7. If file inputed in FileRequest manually and it not exists then shows message


Thank you so much!! Before your reply, I had finally gotten something to work, but your additional code for the delete button and the validations will save me lots of time, thanks again. I really appreciate your help. And by the looks of the download #s, other folks will benefit, too!


Another question - does anyone know what the sendmessage command is to update the value of a FileRequest control? I.e., if the user had used the browse button and the filerequest control states:
c:\abc.txt
How can I change it to something else, not via the browse button? WM_SETTEXT changes the browse button text, but i want the actual filepath text changed. Thanks!


In the script you can change it with:

GetDlgItem $1 $HWND 1200
SendMessage $1 ${WM_SETTEXT} 1 "STR:String"

Hi, thanks for the superfast response! But when i use this code, it seems to only change the browse button's text. But I really want to change the filerequest's value. Do you know how I can do this? Thanks!


If you don't change ini Fields in script then browse button have "item_id"=1201 and filerequest "item_id"=1200. If you change it then just SendMessage to all controls 1200, 1201, 1202,... to find "item_id" :)


Thanks so much! I didn't know that FileREquest consists of actually two controls, I mean, they're grouped together as one field in HM NIS edit, but of course to windows, they're separate! So I used Microsoft Spy to figure out what the control id is and got it to work! Yeah!!

Just two last questions:
1. How do I get the values out of the listbox as one string? I thought the following would work but it didn't:

!insertmacro MUI_INSTALLOPTIONS_READ $FILE_PATH_STRING "ListBox.ini" "Field 4" ListItems

2. Where can I find a reference of which sendmessages are available for which controls, and what arguments are needed?

Again, you've been so tremdously helpful, I hope you didn't mind my asking so many q's!


1. Variables is limited to 1024 bytes (more in special build). I think the best way use stack or text file for export items from ListBox. But I don't known how to get string from ListBox if I have index (trying unsuccessful: LB_GETITEMDATA, LB_GETTEXT).

2. http://msdn.microsoft.com/library/de...incontrols.asp