Skip to content
⌘ NSIS Forum Archive

${NSD_CreateNumber} with up/down arrows (aka "spin control") possible?

11 posts

nsnb#

${NSD_CreateNumber} with up/down arrows (aka "spin control") possible?

I have been trying to find some information on what's known in MFC as "spin control" but I couldn't find any.

Is there a different name for it, or this simply is not supported yet in nsDialogs?

Thanks.
Wizou#
Not yet supported.
Here is what I come up with to add support:
!define UDS_WRAP                0x0001
!define UDS_SETBUDDYINT         0x0002
!define UDS_ALIGNRIGHT          0x0004
!define UDS_ALIGNLEFT           0x0008
!define UDS_AUTOBUDDY           0x0010
!define UDS_ARROWKEYS           0x0020
!define UDS_HORZ                0x0040
!define UDS_NOTHOUSANDS         0x0080
!define UDS_HOTTRACK            0x0100
!define __NSD_UpDown_CLASS msctls_updown32
!define __NSD_UpDown_STYLE ${DEFAULT_STYLES}|${UDS_ARROWKEYS}|${UDS_AUTOBUDDY}
!define __NSD_UpDown_EXSTYLE 0
!insertmacro __NSD_DefineControl UpDown 
then try creating a UpDown control with nsDialogs just after your edit field

Note: I didn't test this.
Animaether#
Wizou's ${NSD_CreateUpDown} code works fine. Just keep in mind that NSD_OnClick and _OnChange will do nothing for the UpDown control, so set _OnChange up on its buddy control (typically a ${NSD_CreateText}) instead.

You may also want to set up some sane range (the default is inverted, for one) and a default value:
!define UDM_SETRANGE 0x0465
!define UDM_SETPOS32 0x0471
[...]
${NSD_CreateText} 0 0 50 16 "0"
  Pop $UpDownBuddy
${NSD_CreateUpDown} 50 0 48 16 ""
  Pop $UpDown
  SendMessage $UpDown ${UDM_SETRANGE} 0 100 ; min max
  SendMessage $UpDown ${UDM_SETPOS32} 0 50 ; 0 value
; Setting up the OnChange callback here to prevent UpDown from triggering it on creation
${NSD_OnChange} $UpDownBuddy custom.updownbuddy.onchange 
If you do use a Buddy control, you might also have to do some sanity checking yourself. E.g. you can enter a value in the Text control that is outside of the UpDown control's range.
nsnb#edited
Wizou and Animaether, thanks for your replies. I tried implementing your code. It displays very well, but when I click the up/down arrows, nothing changes in the buddy. Any idea what could be missing?

Here is my code:

Var hUpDown
Var hUpDownBuddy
Var varUpDownToMM
!define UDM_SETRANGE 0x0465
!define UDM_SETPOS32 0x0471
!define UDM_GETPOS32 0x0472
!define UDS_WRAP                0x0001
!define UDS_SETBUDDYINT         0x0002
!define UDS_ALIGNRIGHT          0x0004
!define UDS_ALIGNLEFT           0x0008
!define UDS_AUTOBUDDY           0x0010
!define UDS_ARROWKEYS           0x0020
!define UDS_HORZ                0x0040
!define UDS_NOTHOUSANDS         0x0080
!define UDS_HOTTRACK            0x0100
!define __NSD_UpDown_CLASS msctls_updown32
!define __NSD_UpDown_STYLE ${DEFAULT_STYLES}|${UDS_ARROWKEYS}|${UDS_AUTOBUDDY}
!define __NSD_UpDown_EXSTYLE 0
!insertmacro __NSD_DefineControl UpDown  
Function custom.updownbuddy.onchange
  SendMessage $hUpDown ${UDM_GETPOS32} 0 0 $varUpDownToMM
FunctionEnd
Function Test
[...]
    ${NSD_CreateLabel} 2 74u 16u 12u "testtext:"
    Pop $hStaticLabel
${NSD_CreateNumber} 26u 72u 24u 12u "2"
  Pop $hUpDownBuddy
${NSD_CreateUpDown} 50u 72u 24u 12u ""
  Pop $hUpDown
  SendMessage $hUpDown ${UDM_SETRANGE} 0 23 ; min max
  SendMessage $hUpDown ${UDM_SETPOS32} 0 50 ; 0 value
; Setting up the OnChange callback here to prevent UpDown from triggering it on creation
${NSD_OnChange} $hUpDownBuddy custom.updownbuddy.onchange  
[...]
FunctionEnd 
Isn't the associated buddy supposed to change automatically upon clicking an up/down arrow? (otherwise it wouldn't have been called a buddy, right?)

There is something I am missing here but I don't know what it is. Any idea?
Animaether#
You have forgotten to include ${UDS_SETBUDDYINT} in your updown control's style.

UDS_SETBUDDYINT

Causes the up-down control to set the text of the buddy window (using the WM_SETTEXT message) when the position changes. The text consists of the position formatted as a decimal or hexadecimal string.
nsnb#
Originally Posted by Animaether View Post
You have forgotten to include ${UDS_SETBUDDYINT} in your updown control's style.
You were right on the money. Thank you Animaether.
Animaether#
I have added a section to the nsDialogs FAQ, where you can also grab the correct method of handling UpDown control interaction:
nsnb#
Originally Posted by Animaether View Post
I have added a section to the nsDialogs FAQ, where you can also grab the correct method of handling UpDown control interaction:
http://nsis.sourceforge.net/mediawik...ol_interaction
Animaether, you rock! Thank you very much.

Now, it would be nice to have the same for the Date and Time Picker 🙂

This section contains information about the API elements used with date and time picker controls.
Animaether#
silly wiki link goes to an edit page.. figures.

here's a regular link: http://nsis.sourceforge.net/mediawik...ol_interaction
Animaether#
nsnb - what did you need that DateTime control for?

I'm miraculously finding myself with a project where I might end up using it ( you must have jynxed me 😉 ).. so I've got all of the important bits going.. but plan on finishing it up into a user-friendly and global variables-eating header file as the bugger is fairly extensive in messages/notifications bits.