Announcement

Collapse
No announcement yet.

Two Scroll Bar in same windows

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

  • Two Scroll Bar in same windows

    Hi,
    I got the below code work with single scroll bar,
    but if I want to have the other one at the same windows
    It can't, I try to understand the example in Petzold, but
    it too difficult for me! I just don,t know how to tell the
    %WM_HScroll to indentify which one is in control.
    Anybody can help with some source add to this? Many Thank.

    #REGISTER NONE

    #COMPILE EXE

    #INCLUDE "win32api.inc"

    %IDC_SCROLL = 100
    %IDC_TEXT = 101
    %My_MIN = 20
    %My_MAX = 3000
    %My_STEP = 10
    %My_INITIAL = 440

    DECLARE CALLBACK FUNCTION DlgProc

    FUNCTION PBMAIN

    LOCAL hDlg AS LONG

    DIALOG NEW 0, "",,, 278, 44, %DS_MODALFRAME OR %DS_CENTER OR %WS_POPUP OR %WS_CAPTION OR %WS_SYSMENU TO hDlg
    CONTROL ADD "SCROLLBAR", hDlg, %IDC_SCROLL, "", 7, 7, 262, 11, %WS_CHILD OR %SBS_HORZ OR %WS_VISIBLE
    CONTROL ADD LABEL, hDlg, %IDC_TEXT, "", 47,24,27,12, %SS_CENTERIMAGE OR %SS_SUNKEN
    DIALOG SHOW MODAL hDlg CALL DlgProc

    END FUNCTION

    CALLBACK FUNCTION DlgProc

    STATIC hwndScroll AS LONG
    STATIC X AS SINGLE

    LOCAL iDummy AS LONG
    LOCAL i AS LONG

    SELECT CASE CBMSG
    CASE %WM_INITDIALOG
    CONTROL HANDLE CBHNDL, %IDC_SCROLL TO hwndScroll
    SetScrollRange hwndScroll, %SB_CTL, %My_MIN*%My_STEP, %My_MAX*%My_STEP, %FALSE
    SetScrollPos hwndScroll, %SB_CTL, %My_INITIAL*%My_STEP, %TRUE
    CONTROL SET TEXT CBHNDL, %IDC_TEXT, FORMAT$(%My_INITIAL)
    X = %My_INITIAL


    CASE %WM_HSCROLL
    SELECT CASE LOWRD(CBWPARAM)
    CASE %SB_LINELEFT : X = 2 ^ (-1 / 12 ) * X
    CASE %SB_LINERIGHT : X = 2 ^ ( 1 / 12 ) * X
    CASE %SB_PAGELEFT : X = X / 2
    CASE %SB_PAGERIGHT : X = X * 2
    CASE %SB_THUMBTRACK : X = HIWRD(CBWPARAM)/%My_STEP
    CASE %SB_TOP : GetScrollRange hwndScroll, %SB_CTL, CLNG(X*%My_STEP), iDummy
    CASE %SB_BOTTOM : GetScrollRange hwndScroll, %SB_CTL, CLNG(X*%My_STEP), iDummy
    END SELECT

    X = MAX(%My_MIN, MIN(%My_MAX, X))
    SetScrollPos hwndScroll, %SB_CTL, CLNG(X*%My_STEP), %TRUE
    CONTROL SET TEXT CBHNDL, %IDC_TEXT, FORMAT$( X,"#.#")

    END SELECT

    END FUNCTION



  • #2
    You need to distinguish the controls by there ID like;
    %IDC_SCROLL = 100

    %IDC_SCROLL2 = 110

    Use CBCTL in %WM_HSCROLL to get the corr. id back.
    Then use if and then...
    Select Case cbctl
    Case %IDC_SCROLL

    '''''''''

    Case %IDC_SCROLL2

    ''''''''''''''

    etc..


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

    Comment


    • #3
      OK I try this method,
      But don't work as well!

      Can Help?

      #REGISTER NONE
      #COMPILE EXE

      #INCLUDE "win32api.inc"

      %IDC_SCROLL = 100
      %IDC_SCROLL2 = 102
      %IDC_TEXT = 101
      %My_MIN = 20
      %My_MAX = 3000
      %My_STEP = 10
      %My_INITIAL = 440

      DECLARE CALLBACK FUNCTION DlgProc

      FUNCTION PBMAIN

      LOCAL hDlg AS LONG

      DIALOG NEW 0, "",,, 278, 100, %DS_MODALFRAME OR %DS_CENTER OR %WS_POPUP OR %WS_CAPTION OR %WS_SYSMENU TO hDlg
      CONTROL ADD "SCROLLBAR", hDlg, %IDC_SCROLL, "", 7, 17, 262, 11, %WS_CHILD OR %SBS_HORZ OR %WS_VISIBLE
      CONTROL ADD "SCROLLBAR", hDlg, %IDC_SCROLL2, "", 7, 55, 262, 11, %WS_CHILD OR %SBS_HORZ OR %WS_VISIBLE
      CONTROL ADD LABEL, hDlg, %IDC_TEXT, "", 47,33,27,12, %SS_CENTERIMAGE OR %SS_SUNKEN
      DIALOG SHOW MODAL hDlg CALL DlgProc

      END FUNCTION

      CALLBACK FUNCTION DlgProc

      STATIC hwndScroll AS LONG
      STATIC hwndScroll2 AS LONG
      STATIC X AS SINGLE

      LOCAL iDummy AS LONG
      LOCAL i AS LONG

      SELECT CASE CBMSG
      CASE %WM_INITDIALOG
      CONTROL HANDLE CBHNDL, %IDC_SCROLL TO hwndScroll
      CONTROL HANDLE CBHNDL, %IDC_SCROLL2 TO hwndScroll2
      SetScrollRange hwndScroll, %SB_CTL, %My_MIN*%My_STEP, %My_MAX*%My_STEP, %FALSE
      SetScrollPos hwndScroll, %SB_CTL, %My_INITIAL*%My_STEP, %TRUE
      SetScrollRange hwndScroll2, %SB_CTL, %My_MIN*%My_STEP, %My_MAX*%My_STEP, %FALSE
      SetScrollPos hwndScroll2, %SB_CTL, %My_INITIAL*%My_STEP, %TRUE
      CONTROL SET TEXT CBHNDL, %IDC_TEXT, FORMAT$(%My_INITIAL)
      X = %My_INITIAL


      CASE %WM_HSCROLL
      SELECT CASE CBCTL
      CASE %IDC_SCROLL

      SELECT CASE LOWRD(CBWPARAM)
      CASE %SB_LINELEFT : X = 2 ^ (-1 / 12 ) * X
      CASE %SB_LINERIGHT : X = 2 ^ ( 1 / 12 ) * X
      CASE %SB_PAGELEFT : X = X / 2
      CASE %SB_PAGERIGHT : X = X * 2
      CASE %SB_THUMBTRACK : X = HIWRD(CBWPARAM)/%My_STEP
      CASE %SB_TOP : GetScrollRange hwndScroll, %SB_CTL, CLNG(X*%My_STEP), iDummy
      CASE %SB_BOTTOM : GetScrollRange hwndScroll, %SB_CTL, CLNG(X*%My_STEP), iDummy
      END SELECT

      X = MAX(%My_MIN, MIN(%My_MAX, X))
      SetScrollPos hwndScroll, %SB_CTL, CLNG(X*%My_STEP), %TRUE
      CONTROL SET TEXT CBHNDL, %IDC_TEXT, FORMAT$( X,"#.#")


      CASE %IDC_SCROLL2

      SELECT CASE LOWRD(CBWPARAM)
      CASE %SB_LINELEFT : X = 2 ^ (-1 / 12 ) * X
      CASE %SB_LINERIGHT : X = 2 ^ ( 1 / 12 ) * X
      CASE %SB_PAGELEFT : X = X / 2
      CASE %SB_PAGERIGHT : X = X * 2
      CASE %SB_THUMBTRACK : X = HIWRD(CBWPARAM)/%My_STEP
      CASE %SB_TOP : GetScrollRange hwndScroll2, %SB_CTL, CLNG(X*%My_STEP), iDummy
      CASE %SB_BOTTOM : GetScrollRange hwndScroll2, %SB_CTL, CLNG(X*%My_STEP), iDummy
      END SELECT

      X = MAX(%My_MIN, MIN(%My_MAX, X))
      SetScrollPos hwndScroll2, %SB_CTL, CLNG(X*%My_STEP), %TRUE
      CONTROL SET TEXT CBHNDL, %IDC_TEXT, FORMAT$( X,"#.#")

      END SELECT

      END SELECT
      END FUNCTION

      Comment


      • #4
        You would need to test for each scroll bar handle, not the
        ID in this case. Check the WM_HSCROLL::lParam for the handle.

        HTH
        Regards, Jules

        Comment


        • #5

          You should be using the GetScrollInfo API function, rather than SetScrollRange. Some API functions are older (not yet obsolete) and should be dropped for the new versions made available in the API.

          Also you are using the CBCTL function and it is possible that it may not contain the correct control ID. The WM_VSCROLL (and WM_HSCROLL) message passes all you need in its lParam and wParam values. The DDT function CBCTL, must know how to process the windows messages parameters to retrieve the controls ID. The DDT functions handle the WM_COMMAND message correctly (which is used by most controls for events), but I am not sure whether the DDT functions will retrieve the correct data (Control ID in this case) for other windows messages like WM_NOTIFY, WM_VSCROLL, WM_HSCROLL.

          I strongly suggest you stick with parsing the wParam and lParam values only , rather than use the DDT functions, when dealing with any message other than WM_COMMAND.

          The PB Docs, don't explain in detail "which" messages the DDT functions will successfully retrieve values for (ie. CBCTL). Callbacks for controls only work with the WM_COMMAND message , as far as I can tell.



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

          Comment


          • #6
            Okay, just tested to make sure.

            Code:
            'rev052600
            #REGISTER NONE
            #COMPILE EXE
             
            #INCLUDE "win32api.inc"
             
            %IDC_SCROLL       =  100
            %IDC_SCROLL2      =  102
            %IDC_TEXT         =  101
            %My_MIN           =    20
            %My_MAX           =  3000
            %My_STEP          =    10
            %My_INITIAL       =   440
             
            GLOBAL hsb1 AS LONG
            GLOBAL hsb2 AS LONG
             
            DECLARE CALLBACK FUNCTION DlgProc
             
            FUNCTION PBMAIN
             
                LOCAL hDlg AS LONG
             
                DIALOG NEW 0, "",,, 278, 100, %DS_MODALFRAME OR %DS_CENTER OR %WS_POPUP OR %WS_CAPTION OR %WS_SYSMENU TO hDlg
                CONTROL ADD "SCROLLBAR", hDlg, %IDC_SCROLL, "", 7, 17, 262, 11, %WS_CHILD OR %SBS_HORZ OR %WS_VISIBLE
                CONTROL ADD "SCROLLBAR", hDlg, %IDC_SCROLL2, "", 7, 55, 262, 11, %WS_CHILD OR %SBS_HORZ OR %WS_VISIBLE
                CONTROL ADD LABEL, hDlg, %IDC_TEXT, "", 47,33,27,12, %SS_CENTERIMAGE OR %SS_SUNKEN
                DIALOG SHOW MODAL hDlg CALL DlgProc
             
            END FUNCTION
             
            CALLBACK FUNCTION DlgProc
             
                STATIC hwndScroll AS LONG
                STATIC hwndScroll2 AS LONG
                STATIC X AS SINGLE
             
                LOCAL iDummy AS LONG
                LOCAL i AS LONG
             
                SELECT CASE CBMSG
                CASE %WM_INITDIALOG
                    CONTROL HANDLE CBHNDL, %IDC_SCROLL TO hwndScroll
                    CONTROL HANDLE CBHNDL, %IDC_SCROLL2 TO hwndScroll2
                      
                    hsb1 = hwndscroll
                    hsb2 = hwndscroll2
                     
                    SetScrollRange hwndScroll, %SB_CTL, %My_MIN*%My_STEP, %My_MAX*%My_STEP, %FALSE
                    SetScrollPos hwndScroll,   %SB_CTL, %My_INITIAL*%My_STEP, %TRUE
                    SetScrollRange hwndScroll2, %SB_CTL, %My_MIN*%My_STEP, %My_MAX*%My_STEP, %FALSE
                    SetScrollPos hwndScroll2,   %SB_CTL, %My_INITIAL*%My_STEP, %TRUE
                    CONTROL SET TEXT CBHNDL, %IDC_TEXT, FORMAT$(%My_INITIAL)
                    X = %My_INITIAL
             
             
                CASE %WM_HSCROLL
             
                     SELECT CASE CBLPARAM
                       
                     CASE hsb1 '%IDC_SCROLL
             
             
                        SELECT CASE LOWRD(CBWPARAM)
                        CASE %SB_LINELEFT   : X = 2 ^ (-1 / 12  ) * X
                        CASE %SB_LINERIGHT  : X = 2 ^ ( 1 / 12 ) * X
                        CASE %SB_PAGELEFT   : X = X / 2
                        CASE %SB_PAGERIGHT  : X = X * 2
                        CASE %SB_THUMBTRACK : X = HIWRD(CBWPARAM)/%My_STEP
                        CASE %SB_TOP        : GetScrollRange hwndScroll, %SB_CTL, CLNG(X*%My_STEP), iDummy
                        CASE %SB_BOTTOM     : GetScrollRange hwndScroll, %SB_CTL, CLNG(X*%My_STEP), iDummy
                        END SELECT
             
                         X = MAX(%My_MIN, MIN(%My_MAX, X))
                        SetScrollPos hwndScroll, %SB_CTL, CLNG(X*%My_STEP), %TRUE
             
                        CONTROL SET TEXT CBHNDL, %IDC_TEXT, FORMAT$( X,"#.#")
             
             
                    CASE hsb2 '%IDC_SCROLL2
             
                        SELECT CASE LOWRD(CBWPARAM)
                        CASE %SB_LINELEFT   : X = 2 ^ (-1 / 12  ) * X
                        CASE %SB_LINERIGHT  : X = 2 ^ ( 1 / 12 ) * X
                        CASE %SB_PAGELEFT   : X = X / 2
                        CASE %SB_PAGERIGHT  : X = X * 2
                        CASE %SB_THUMBTRACK : X = HIWRD(CBWPARAM)/%My_STEP
                        CASE %SB_TOP        : GetScrollRange hwndScroll2, %SB_CTL, CLNG(X*%My_STEP), iDummy
                        CASE %SB_BOTTOM     : GetScrollRange hwndScroll2, %SB_CTL, CLNG(X*%My_STEP), iDummy
                        END SELECT
             
                        X = MAX(%My_MIN, MIN(%My_MAX, X))
                        SetScrollPos hwndScroll2, %SB_CTL, CLNG(X*%My_STEP), %TRUE
                        CONTROL SET TEXT CBHNDL, %IDC_TEXT, FORMAT$( X,"#.#")
             
                END SELECT
             
            END SELECT
            END FUNCTION
            Regards, Jules

            Comment


            • #7
              You can use the API function , GetDlgCtrlID , to get a controls ID , if you know its handle (which is passed in the WM_VSCROLL and WM_HSCROLL messages).

              ie.

              CtrlID=GetDlgCtrlID(hScroll)



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

              Comment


              • #8
                Thank! Jules,

                I see this work at Last!
                I spend the passed 24 hrs for this.
                I can go and sleep now!


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

                Comment


                • #9
                  Essentially, the built-in DDT "variables" CBHNDL, CBCTL, CBCTLMSG, etc, are not "translated" in any way... they are exactly that would be received in the equivalent variables with a "classic" SDK-style callback function... FUNCTION DlgCallback(BYVAL hWnd&, BYVAL wMsg&, BYVAL wParam&, BYVAL lParam&) AS LONG

                  Code:
                  CBHNDL   = hWnd
                  CBMSG    = wMsg
                  CBWPARAM = wParam
                  CBLPARAM = lParam
                  CBCTLMSG = HIWRD(wParam)
                  CBCTL    = LOWRD(wParam)
                  ...etc
                  Because there is no message-dependent translation going on, it is up to you, the programmer, to interpret the values contained in these "variables" according to the type of message being received.

                  For example, in such messages where wParam contains other than a control ID and notification code (such as %WM_PAINT), CBCTL and CBCTLMSG may me meaningless with respect to control ID and notification codes... it depends on the message.

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

                  Comment


                  • #10
                    Aisin Geuru Suen Yue, Your welcome!

                    Make sure you download the win32api help file from PB's it's worth
                    the wait while downloading it. (~7mb)

                    I did not know this on the top of my head, I only code a little at a time,
                    when I have time and I have minimal and I mean minimal Windows programming
                    experience. I just had to put the cursor on the word WM_HSCROLL and
                    press F1 and that lead me to the answer.

                    Since you are into Robotics and so am I, do you have any PB code that will
                    convert Gerber files into XYZ strings for a simple stepper motor
                    drive scheme CNC table?

                    Regards, Jules

                    Comment


                    • #11
                      Hi Jules,

                      Are you try to make a PCB router?
                      I am new to PB, so I don't have much code,
                      But I can ask some of my engineer,see whether
                      they have similar code in C or dos Basic.
                      If you can let me know more about your idea,
                      may be I can provide some reference.
                      my.address:: [email protected]
                      Have a nice day



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

                      Comment

                      Working...
                      X