Archive: currency selection drop down


currency selection drop down
  Hi,

How can i give a drop down list to select standard set of currency in the installation page. There are more then 100 currency which i want to give, so is there any plugin or a way by which i can provide this option in the installation page.

Thank you for any kind of help.


nsDialogs and a listbox should be all you need. You could hard-code the currencies, or you can include a flat text file with your installer to build the list at runtime.

!include "LogicLib.nsh"
!include "MUI2.nsh"
!include "winMessages.nsh"
!include "nsDialogs.nsh"

OutFile "test.exe"

Section
SectionEnd

Var dialog
Var hwnd
Var null

Var hwnd_listbox

/* A variable to hold the currency the user selects */
Var currency

Page Custom customPage

Function .onInit
InitPluginsDir
FunctionEnd

Function customPage
nsDialogs::Create 1018
Pop $dialog

/* Extract a list of currencies */
SetOutPath "$PluginsDir"
File "currencies.txt"

/* Create a list box */
${NSD_CreateListBox} 0 0 50% 100% ""
Pop $hwnd_listbox

/* Populate it with our list of currencies */
FileOpen $0 "$PluginsDir\currencies.txt" "r"
FileRead $0 $1
ClearErrors
${DoUntil} ${Errors}
${NSD_LB_AddString} $hwnd_listbox $1
FileRead $0 $1
${Loop}
FileClose $0

/* Add a callback for when the user selects a currency */
${NSD_OnChange} $hwnd_listbox customPage.listbox.onchange

/* Disabe the Next/Close button - the user -must- pick a currency */
/* (none are selected by default in this example) */
GetDlgItem $0 $HWNDPARENT 1
EnableWindow $0 0

nsDialogs::Show
FunctionEnd

Function customPage.listbox.onchange
Pop $hwnd

/* Store the selected currency in the $currency variable */
${NSD_LB_GetSelection} $hwnd_listbox $currency

/* Enable the Next/Close button */
GetDlgItem $0 $HWNDPARENT 1
EnableWindow $0 1
FunctionEnd
!insertmacro MUI_LANGUAGE "English"
With the content of "currencies.txt" being something like (up to you, of course):

EUR - Euro
USD - U.S. Dollars
GBP - United Kingdom Pounds

You could enumerate all system local names with EnumSystemLocalesEx, and then get the currency of that local with GetLocaleInfoEx (using LOCALE_SCURRENCY as LCType) using the System plugin to get rid of the text file.
But I don't say that it'll be easy...


You might run into an issue with missing currencies or the converse.. getting currencies you do not support. Making your own list would preclude such issues.

Depends on the author's intent of the list, of course =)


Thank you very much @Animaether but i want a drop list in place of list Box.


Thank you for such a great help well i want a drop list in place of the list box. So how can i achieve it.


Thanks a lot everybody i got the mistake i was making its NSD_CB_AddString in place of NSD_LB_AddString for a Drop List. ;)


yeah, they're different messages - glad you got it :)


HI Animaether,

Can you please tell me how to select default value in the drop down list ?? like i want to select 37th entry of my drop down list as the default value. so how can i achieve it.

There is one more issue i am facing with the first entry of the drop list "i>>J" kind of next is coming. Although i am not passing anything like that. For the reference i am attaching the currency drop list file.

Thank you very much in advance.


Originally posted by nick_goyal
Can you please tell me how to select default value in the drop down list ?? like i want to select 37th entry of my drop down list as the default value. so how can i achieve it.
Probably the sanest way is to select by string using NSD's own macros:
***91;...***93;

${
Loop}
FileClose $0
${NSD_CB_SELECTSTRING} $hwnd_listbox "Ghana, Cedis"
>***91;...***93;
If you absolutely must select by index, you'd use:
***91;...***93;

${
Loop}
FileClose $0
SendMessage $hwnd_listbox${CB_SETCURSEL} 36 0
>***91;...***93;
Note that the index is zero-based.. so to select the 37th, you pass 36 to the SendMesage command.


Originally posted by nick_goyal
There is one more issue i am facing with the first entry of the drop list "i>>J" kind of next is coming. Although i am not passing anything like that. For the reference i am attaching the currency drop list file.
Good thing you attached the file :) Your currencies.txt file is in Unicode. That gobbledygook you see in front of the first entry is the BOM (Byte Order Mark).
Re-saving with an ANSI codepage should sort it right out. If you need to keep it as Unicode for any particular reason, you'll have to treat it as such :)

Hi Animaether,

Thank you very much for the great help. Problem solved:up:


I think you should give first the drop down list to select standard set of currency in the installation page in order for us to tell if there are any plugin or a way by which you can provide this option in the installation page.