Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

Minimalist UpDown (Spinner Control) DDT Demo

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • PBWin Minimalist UpDown (Spinner Control) DDT Demo

    '
    Code:
    #COMPILE EXE
    #DIM ALL
    #INCLUDE ONCE "WIN32API.INC"
    
    ENUM ctls SINGULAR
    IDC_UpDown = 1001
    IDC_txtBuddy
    IDC_txtInfo
    IDC_btnIncr
    END ENUM
    
    FUNCTION PBMAIN () AS LONG
        LOCAL lRslt AS LONG
        LOCAL hDlg  AS DWORD
        LOCAL hFont1 AS DWORD
        FONT NEW "Arial Unicode",20,0,0,0 TO hFont1
        DIALOG NEW 0, "UP/Down Demo", , , 150, 150,%WS_OVERLAPPEDWINDOW TO Hdlg
    
            CONTROL ADD "msctls_updown32", hDlg, %IDC_UpDown, "", 95, 40, 15, 30, _
                   %WS_CHILD OR %WS_VISIBLE OR %UDS_SETBUDDYINT OR %UDS_ARROWKEYS OR %UDS_NOTHOUSANDS
            CONTROL ADD TEXTBOX, hDlg, %IDC_txtBuddy, "", 40, 46, 50, 20, _
                   %WS_CHILD OR %WS_VISIBLE OR %ES_NUMBER
            CONTROL SET FONT hDlg,%IDC_txtBuddy,hFont1
            CONTROL ADD TEXTBOX, hDlg, %IDC_txtInfo, "", 10, 100, 135, 15
            CONTROL ADD BUTTON,  hDlg, %IDC_btnIncr, "Incr", 100, 10, 40, 20
        DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt
        FUNCTION = lRslt
    END FUNCTION
    
    CALLBACK FUNCTION ShowDIALOG1Proc()
        LOCAL hCtrl AS DWORD
        LOCAL lRet AS LONG
        LOCAL iMax,iMin AS INTEGER
        LOCAL strT AS STRING
        SELECT CASE AS LONG CB.MSG
            CASE %WM_INITDIALOG
                 'Make the text box  the buddy to the UpDown control
                CONTROL HANDLE CB.HNDL, %IDC_txtBuddy TO hCtrl
                CONTROL SEND   CB.HNDL, %IDC_UpDown,%UDM_SETBUDDY, hCtrl, %NULL
                ' set the range for the UpDown control
                iMax = 9999
                iMin =  0
                CONTROL SEND CB.HNDL, %IDC_UpDown,%UDM_SETRANGE, %NULL, MAKLNG(iMax, imin)
                'set the initial value of the UpDown control
                iMin        = 500
                CONTROL SEND CBHNDL, %IDC_UpDown,%UDM_SETPOS, %NULL, MAKLNG(iMin, 0)
    
            CASE %WM_COMMAND
                SELECT CASE CB.CTL
                    CASE %IDC_txtBuddy
                         IF CB.CTLMSG = %EN_CHANGE THEN
                             CONTROL GET TEXT CB.HNDL ,CB.CTL TO strT
                             CONTROL SET TEXT CB.HNDL,%IDC_txtInfo, "Changed to " & strT
                         END IF
                    CASE %IDC_btnIncr  ' Programmatically increment the UpDown control
                         IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN
                            CONTROL SEND CB.HNDL,%IDC_UpDown, %UDM_GETPOS,0,0 TO lRet
                            CONTROL SEND CB.HNDL, %IDC_UpDown, %UDM_SETPOS,%NULL,(lRet+1)
                         END IF
                END SELECT
    
    
            CASE %WM_NOTIFY
              IF (CB.NMID = %IDC_UPDOWN) THEN
                IF CB.NMCODE = %UDN_DELTAPOS THEN
                  LOCAL lpNMUPDOWN AS NM_UPDOWN PTR
                    lpNMUPDOWN = CB.LPARAM
                    IF @lpNMUPDOWN.iDelta > 0 THEN
                        DIALOG SET TEXT CB.HNDL, "Up from " & STR$(@lpNMUPDOWN.iPos)
                    ELSE
                        DIALOG SET TEXT CB.HNDL, "Down from" & STR$(@lpNMUPDOWN.iPos)
                    END IF
              END IF
              END IF
        END SELECT
    END FUNCTION
    '

    Note: Adding a "CONTROL HIDE hDlg, %IDC_txtBuddy " allows you to still trap the value of the UpDown without displaying it directly.
    You can still take any action desired in the %EN_CHANGE event of the buddy textbox.
    Last edited by Stuart McLachlan; 22 Sep 2020, 12:42 AM.

  • #2
    Extra code for post #1 callback to demo use of UDN_DELTAPOS notification of up/down arrow button click (or arrow key press).
    Code:
            CASE %WM_NOTIFY
              IF (CB.NMID = %IDC_UPDOWN) THEN
                IF CB.NMCODE = %UDN_DELTAPOS THEN
                  LOCAL lpNMUPDOWN AS NM_UPDOWN PTR
                    lpNMUPDOWN = CB.LPARAM
                    IF @lpNMUPDOWN.iDelta > 0 THEN SetWindowText CB.HNDL, "Up from " + STR$(@lpNMUPDOWN.iPos) _
                                              ELSE SetWindowText CB.HNDL, "Down from" + STR$(@lpNMUPDOWN.iPos)
                END IF
              END IF
    Rgds, Dave

    Comment


    • #3
      1. Added Dave's concept to original listing (thanks Dave) - but kept it DDT by using DIALOG SET TEXT rather than SetWindowsText
      2. Added a button to demonstrate programmatically reading and changing the UpDown position.

      Comment


      • #4
        One more addition:
        Increase the step size if the mouse is held down on an arrow for x seconds.
        Include in %WM_INITDIALOG
        Code:
        DIM udAcc(2) AS UDACCEL 'array of accelerator structures (we will use 3)
        LOCAL udptr AS UDACCEL PTR
        udptr = VARPTR(udAcc(0))
        
        udAcc(0).nsec = 0 'initially
        udAcc(0).nInc = 1 'step by 1
        udAcc(1).nsec = 2 'after 2 seconds
        udAcc(1).nInc = 10 'step by 10
        udAcc(2).nsec = 5 'after 5 seconds
        udAcc(2).nInc = 50 'step by 50
        
        'wParam = number of Accelerator structures, lParam pointer to first member of array
        CONTROL SEND CB.HNDL, %IDC_UpDown,%UDM_SETACCEL,3,udptr

        Comment

        Working...
        X