dougcvc
16th November 2009 03:44 UTC
nsdialogs combobox problem
Hello,
I am having a problem with a nsdialogs combo box list which seems to behave differently when i type something in to when i click and select an option from the list.
I add A, B , and C to the list and have ${NSD_OnChange} bring up a message when it is changed. If i type C in to the box the ${NSD_OnChange} messagebox says "C", whereas if i select "C" in the drop down box it still says "A".
I cant figure out what im doing wrong however.
Here is some example code..
Name test
OutFile test.exe
!include nsDialogs.nsh
XPStyle on
Page custom nsDialogsPage
Page instfiles
var /global Dialog
var /global COMBOBOX
Function nsDialogsPage
nsDialogs::Create 1018
Pop $Dialog
${If} $Dialog == error
Abort
${EndIf}
${NSD_CreateComboBox} 0 30 80% 12u "test"
pop $COMBOBOX
${NSD_CB_AddString} $COMBOBOX A
${NSD_CB_AddString} $COMBOBOX B
${NSD_CB_AddString} $COMBOBOX C
${NSD_CB_SelectString} $COMBOBOX A
${NSD_OnChange} $COMBOBOX SourceChanged
nsDialogs::Show
FunctionEnd
Function SourceChanged
${NSD_GetText} $COMBOBOX $0
messagebox mb_ok "selection is $0"
FunctionEnd
Section ""
SectionEnd
Thanks for any help!
pengyou
17th November 2009 19:11 UTC
Use a "leave" function to retrieve the combo box selection
Name test
OutFile test.exe
RequestExecutionLevel "user"
!include nsDialogs.nsh
XPStyle on
Page custom nsDialogsPage nsDialogsPageLeave
Page instfiles
var /global Dialog
var /global COMBOBOX
Function nsDialogsPage
nsDialogs::Create 1018
Pop $Dialog
${If} $Dialog == error
Abort
${EndIf}
${NSD_CreateComboBox} 0 30 80% 12u "test"
pop $COMBOBOX
${NSD_CB_AddString} $COMBOBOX A
${NSD_CB_AddString} $COMBOBOX B
${NSD_CB_AddString} $COMBOBOX C
${NSD_CB_SelectString} $COMBOBOX A
nsDialogs::Show
FunctionEnd
Function nsDialogsPageLeave
${NSD_GetText} $COMBOBOX $0
messagebox mb_ok "selection is $0"
FunctionEnd
Section ""
SectionEnd
dougcvc
17th November 2009 21:59 UTC
Hey thanks alot for the suggestion.
Unfortunately i wanted to work some stuff out on that page and display the results on that page (I am filling the combobox with drive letters / directories and want to display the sizes using getsize/drivespace to get of the selected / entered one on that page before continuing.)
I have looked in to using Winmessages.nsh but cant quite figure it out either. I might just resort to using a droplistbox which seems to work.
Many thanks !
Krasnoff64
23rd November 2009 11:26 UTC
Hy there, I had the same problem. I have solved it by using messages, such as CB_GETCURSEL & CB_GETLBTEXT.
Here is a full text:
Var hCombo
Var PrevIdx
Function OnComboChange
SendMessage $hCombo ${CB_GETCURSEL} 0 0 $0
${If} $PrevIdx == $0
${NSD_GetText} $hCombo $2
${Else}
System::Alloc 64
Pop $1
SendMessage $hCombo ${CB_GETLBTEXT} $0 $1
System::Call "*$1(&t32.r2)"
System::Free $1
${EndIf}
StrCpy $PrevIdx $0
MessageBox MB_OK $2
FunctionEnd
Function Create
; ...
${NSD_CreateComboBox} 75% 85% 20% 20 ""
Pop $hCombo
${NSD_CB_AddString} $hCombo "x"
${NSD_CB_AddString} $hCombo "y"
SendMessage $hCombo ${CB_GETCURSEL} 0 0 $PrevIdx
${NSD_OnChange} $hCombo OnComboChange
; ...
FunctionEnd