Announcement

Collapse
No announcement yet.

Retrieve Updown Value

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

  • Retrieve Updown Value

    I am using several updown controls in a dialog. When I try to retrieve the
    current value of the control, it returns the previous value.

    ex.

    CASE %WM_NOTIFY
    SELECT CASE CBCTL
    CASE %IDC_SPIN1
    CONTROL SEND CBHNDL,CBCTL,%UDM_GETPOS,0,0 TO value&


    In this case, the "value&" variable is filled with the buddy control
    text before pressing the updown control. How do I get the value it is change to?


    Jeff


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

  • #2
    I'm not 100% sure about previewing the change, but you could take a look at the %UDN_DELTAPOS notification message...

    Alternatively, you couls also try using CALL PostMessage(hDlg&, %WM_USER + 999%,...) in the %WM_NOTIFY handler to send yourself a message, and then retrieve the value in the buddy control in response to the %WM_USER + 999& message handler.

    Disclaimer: I've not tried either of these approaches, so YMMV.



    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>
    Lance
    mailto:[email protected]

    Comment


    • #3
      Lance, thanks as always for the response.

      What is the best approach? I change the updown and want to record
      the new value. This is obvious. However, Microsoft apparently had
      something else in mind. Apart for your suggestion, is my only option to read
      the buddy label before ending the dialog? This seems strange to me.

      Jeff

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

      Comment


      • #4
        My first sugestion seems to be the easiest... here is an example based upon my UP-DOWN code circa Jan 2000...
        Code:
        ' DDT Up-Down demo by Lance C. Edmonds ([email protected])
        ' Concept loosely based on the Nancy Clutz much larger resource-script-based code.
        
        #COMPILE EXE
        #DIM ALL
        #INCLUDE "WIN32API.INC"
        #INCLUDE "COMMCTRL.INC"
         
        %ID_LABEL  = 100
        %ID_BUDDY  = 101
        %ID_UPDOWN = 102
         
        %MAX_SPIN  = 10
        %MIN_SPIN  = 1
         
        DECLARE CALLBACK FUNCTION DlgCallback()
         
        FUNCTION PBMAIN
            DIM hDlg AS LONG
         
            CALL InitCommonControls
         
            DIALOG NEW 0, "DDT Up-Down demo",,, 130, 78, %WS_SYSMENU TO hDlg
            CONTROL ADD LABEL, hDlg, %ID_LABEL, "How Many Lines?", 16, 14, 58, 14
            CONTROL ADD TEXTBOX, hDlg, %ID_BUDDY, "1", 77, 12, 26, 12, %ES_AUTOHSCROLL OR %ES_LEFT, %WS_EX_CLIENTEDGE
            CONTROL ADD BUTTON, hDlg, %IDOK, "&OK", 13, 41, 40, 14, %BS_DEFAULT OR %WS_TABSTOP
            CONTROL ADD BUTTON, hDlg, %IDCANCEL, "Cancel", 76, 41, 40, 14
         
            CONTROL ADD "msctls_updown32", hDlg, %ID_UPDOWN, "", 0, 0, 8, 8, %WS_CHILD OR _
                %WS_BORDER OR %WS_VISIBLE OR %UDS_WRAP OR %UDS_ARROWKEYS OR _
                %UDS_ALIGNRIGHT OR %UDS_SETBUDDYINT
         
            CONTROL SEND hDlg, %ID_UPDOWN, %UDM_SETBUDDY, GetDlgItem(hDlg, %ID_BUDDY), 0&
            CONTROL SEND hDlg, %ID_UPDOWN, %UDM_SETRANGE, 0&, MAKLNG(%MAX_SPIN, %MIN_SPIN)
         
            DIALOG SHOW MODAL hDlg CALL DlgCallback
        END FUNCTION
         
        CALLBACK FUNCTION DlgCallback()
            IF CBMSG = %WM_INITDIALOG THEN
                CONTROL SET FOCUS CBHNDL, %IDOK
                FUNCTION = 1
            ELSEIF CBMSG = %WM_COMMAND THEN
                IF CBCTL = %IDOK OR CBCTL = %IDCANCEL THEN
                    DIALOG END CBHNDL, (CBCTL = %IDOK)
                END IF
            ELSEIF CBMSG = %WM_NOTIFY THEN
                DIM pNmUpDown AS NM_UPDOWN PTR
                pNmUpDown = CBLPARAM
                IF @pNmUpDown.hdr.code = %UDN_DELTAPOS THEN
                    SetWindowText CBHNDL, "Preview value =" + STR$(@pNmUpDown.iPos + @pNmUpDown.iDelta)
                END IF
            END IF
        END FUNCTION

        ------------------
        Lance
        PowerBASIC Support
        mailto:[email protected][email protected]</A>
        Lance
        mailto:[email protected]

        Comment


        • #5
          I never tried using UDM_GETPOS. What I used was VAL(GetDlgItemText) of the buddy window.

          As I look over the MSDN info on this, I notice UDM_GETPOS returns an INDEX rather than a value; I wonder if you do a UDM_GETPOS, maybe you need to multiply by the value of the base. When the base is one, it's immaterial; maybe not so when the base is non-one.

          (You don't show if you are using a "step" of other than the default of one).

          MCM
          Michael Mattias
          Tal Systems (retired)
          Port Washington WI USA
          [email protected]
          http://www.talsystems.com

          Comment


          • #6
            The problem with GetDlgItemText is that is "post-operative"... you only get the value once it has been changed.

            By using UDN_DELTAPOS we can "preview" the next step value and make decisions on whether to accept, change or discard the new value before it becomes assigned to the control.

            In my example I used the default STEP of 1, with a range to 1 to 10. Feel free to modify the code to suit your own needs!

            ------------------
            Lance
            PowerBASIC Support
            mailto:[email protected][email protected]</A>
            Lance
            mailto:[email protected]

            Comment


            • #7
              Jeffrey;

              The updown control generates the %WM_VSCROLL message and then you
              can use

              Code:
              P&=LOWRD(SendMessage(hUpDownCtrl&, %UDM_GETPOS,0,0))
              to get the current postion of the control.

              In my apps, I trap both the %WM_VSCROLL and the %WM_HSCROLL messages
              together for the UpDown control.

              I am not sure why you are using the %WM_NOTIFY message.

              Both UpDown controls and TrackBar controls send the %WM_VSCROLL
              (or %WM_HSCROLL) like the Scrollbars do !



              ------------------
              Chris Boss
              Computer Workshop
              Developer of "EZGUI"
              http://cwsof.com
              http://twitter.com/EZGUIProGuy

              Comment


              • #8
                Jeffrey;

                You should have read the API docs.

                Below is a summary of what it says:


                ------------------------------------------
                The UDN_DELTAPOS notification message
                is sent when the position of the control is about to change.]

                The UDN_DELTAPOS message is sent before the WM_VSCROLL message
                that actually changes the control's position.

                This lets you examine, allow, modify, or disallow the change.
                ------------------------------------------

                This means the notification message you are using is sent
                before the control changes value. The correct message
                to process when the control actually changes is
                %WM_VSCROLL as I mentioned above.

                Understanding how to use an UpDown control is very well explained
                in the book "Windows 98 Programming from the Ground Up" by Herbert Schildt !



                ------------------
                Chris Boss
                Computer Workshop
                Developer of "EZGUI"
                http://cwsof.com
                http://twitter.com/EZGUIProGuy

                Comment


                • #9
                  In this case, the %WM_NOTIFY message gives you the current and delta values within the NM_UPDOWN structure... as this message along with a pointer to the required data) is sent to the parent window anyway, it makes perfect sense to use it... ignoring it would be a waste of a perfectly good message

                  Conversely, using scroll messages means additional API calls to get the state, etc. Out of curiousity, how easy is it to "preview" the control's value ahead of the change when you intercept scroll messages?



                  ------------------
                  Lance
                  PowerBASIC Support
                  mailto:[email protected][email protected]</A>
                  Lance
                  mailto:[email protected]

                  Comment


                  • #10
                    Thanks for the replies guys,

                    Lance, your example was the easiest to implement in my situation
                    and everything works fine now.

                    Chris, I would have never thought to check a scroll event on the
                    updown control. I usually look at the MSDN library for a direct
                    message to use. In this case, its a little more involved.

                    Thanks again,

                    Jeff

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

                    Comment


                    • #11
                      Lance,
                      In your example of up-down, you have a buddy window by default,
                      if I am correct, simply by only having one client window. If I
                      place this in my code with several text boxes and then use the
                      positional reference of 0,0 as in you Control Add "msctls_..."
                      statement, I end up at 0,0 of the main dialog.

                      How do you tell the function that a certain textbox is the buddy
                      window and to have the spin buttons point to and use that. I
                      just do not see anything about how to do this, although the
                      winapi help talks about buddy windows and shows how to specify
                      it in the api call.
                      --Barry


                      ------------------
                      Barry

                      Comment


                      • #12
                        Hi Barry,

                        I haven't used this personally since I usually use the autobuddy feature.
                        However, try the %UDM_SETBUDDY message using the handle of the
                        control you wish to make a buddy.



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

                        Comment


                        • #13
                          jeffery and lance
                          thanks.. i did find good comments (remarks) in the http://www.powerbasic.com/support/pb...ad.php?t=22865 message
                          on the chi-squared test

                          my probelm was having the id's wrong:

                          control send hdlg, %id_updown, %udm_setbuddy, getdlgitem(hdlg, %id_buddy), 0&
                          i had the same id for up/down and for the buddy window. changing it
                          fixed everything.

                          --barry



                          ------------------
                          Barry

                          Comment

                          Working...
                          X