Announcement

Collapse
No announcement yet.

Trackbar zero to 255 bottoms up

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

  • Trackbar zero to 255 bottoms up

    A little bit of a brain cramp, ...can the trackbar be flipped to work from bottom 0 to top 255 ? Demo below works from top 0 to bottom 255.

    Thx.
    Regards,
    Jules

    Code:
    #COMPILE EXE
    #DIM ALL
     
    '---Includes...
    #INCLUDE "WIN32API.INC"
    #INCLUDE "COMMCTRL.INC"
    #INCLUDE "PBForms.INC"
    
    '---Constants...
    %IDD_Form1           =  101  'main form
     
    %IDC_VTrackbar1      = 1601
    %IDC_Label3          = 1602
    %IDC_VTrackbar2      = 1603
    %IDC_Label4          = 1604
     
    %IDC_Frame2          = 1801
    %IDC_Frame3          = 1802
    
    %DAC_MAX             = 255
    %DAC_MIN             = 0
    
    '---Delcares...
    DECLARE CALLBACK FUNCTION ShowForm1Proc()
    DECLARE FUNCTION ShowForm1(BYVAL hParent AS DWORD) AS LONG
    
    '------------------------------------------------------------------------------
    '
    '------------------------------------------------------------------------------
    SUB UpdateAnalogOutputStatus(BYVAL hDlg AS DWORD, BYVAL dac1 AS BYTE, BYVAL dac2 AS BYTE)
        
        '-update the position of the  trackbars
        ' not necessary like scrollbars, but caller can set it manually with this call.
        CONTROL SEND hDlg,%IDC_VTrackbar1,%TBM_SETPOS,%TRUE, dac1
        CONTROL SEND hDlg,%IDC_VTrackbar2,%TBM_SETPOS,%TRUE, dac2
    
        '-update the values
        CONTROL SET TEXT hDlg,%IDC_Label3, STR$(dac1)
        CONTROL SET TEXT hDlg,%IDC_Label4, STR$(dac2)
    
    END SUB
    
    '------------------------------------------------------------------------------
    '
    '------------------------------------------------------------------------------
    FUNCTION PBMAIN()
        PBFormsInitComCtls( %ICC_WIN95_CLASSES OR %ICC_DATE_CLASSES OR %ICC_INTERNET_CLASSES ) 'Macro
        CALL ShowForm1(%HWND_DESKTOP)
    END FUNCTION
    
    '------------------------------------------------------------------------------
    '
    '------------------------------------------------------------------------------
    CALLBACK FUNCTION ShowForm1Proc()
        LOCAL lrt AS LONG
        LOCAL cstatus AS STRING
        STATIC cardAddress AS LONG
        LOCAL tPos1 AS LONG, tPos2 AS LONG
        '---
        SELECT CASE AS LONG CBMSG
            '---
            CASE %WM_INITDIALOG
                '-initialize trackbars...
                CONTROL SEND CBHNDL,%IDC_VTrackbar1,%TBM_SETRANGE,%TRUE,MAKDWD(0,255) 'set range
                CONTROL SEND CBHNDL,%IDC_VTrackbar1,%TBM_SETTICFREQ,8,0   'set tic frequency
                CONTROL SEND CBHNDL,%IDC_VTrackbar1,%TBM_SETPAGESIZE,0,10 'set page size
                CONTROL SEND CBHNDL,%IDC_VTrackbar2,%TBM_SETRANGE,%TRUE,MAKDWD(0,255) 'set range
                CONTROL SEND CBHNDL,%IDC_VTrackbar2,%TBM_SETTICFREQ,8,0   'set tick frequency
                CONTROL SEND CBHNDL,%IDC_VTrackbar2,%TBM_SETPAGESIZE,0,10 'set page size
                CALL UpdateAnalogOutputStatus(CBHNDL,%DAC_MIN,%DAC_MIN)   'set thumb pos to min
            '---
            CASE %WM_NCACTIVATE
                STATIC hWndSaveFocus AS DWORD
                IF ISFALSE CBWPARAM THEN
                    hWndSaveFocus = GetFocus()
                ELSEIF hWndSaveFocus THEN
                    SetFocus(hWndSaveFocus)
                    hWndSaveFocus = 0
                END IF
            '---
            CASE %WM_COMMAND
                SELECT CASE AS LONG CBCTL
                END SELECT
            '---
            CASE %WM_VSCROLL '-handle both trackbars...
                SELECT CASE LOWRD(CBWPARAM)
                    CASE %TB_THUMBTRACK, _   '-Mouse
                         %TB_LINEDOWN,   _   '-Keyboard
                         %TB_LINEUP,     _   '-Keyboard
                         %TB_PAGEDOWN,   _   '-Keyboard
                         %TB_PAGEUP,     _   '-Keyboard
                         %TB_TOP,        _   '-Keyboard
                         %TB_BOTTOM          '-Keyboard
                        CONTROL SEND CBHNDL,%IDC_VTrackbar1,%TBM_GETPOS,0,0 TO tPos1
                        CONTROL SEND CBHNDL,%IDC_VTrackbar2,%TBM_GETPOS,0,0 TO tPos2
                        tPos1 = LOWRD(tPos1) : tPos2 = LOWRD(tPos2)
                        CALL UpdateAnalogOutputStatus(CBHNDL,tPos1,tPos2)
                END SELECT
            '---
            CASE %WM_DESTROY
            '---
            CASE %WM_CLOSE
        END SELECT
    END FUNCTION
    
    '------------------------------------------------------------------------------
    '
    '------------------------------------------------------------------------------
    FUNCTION ShowForm1(BYVAL hParent AS DWORD) AS LONG
    
        LOCAL lRslt  AS LONG
        LOCAL hDlg   AS DWORD
        LOCAL hFont1 AS DWORD
    
        DIALOG NEW hParent, "trackbar behavior, temp...", 131, 82, 406, 211, %WS_POPUP OR _
            %WS_VISIBLE OR %WS_CLIPSIBLINGS OR %WS_BORDER OR %WS_DLGFRAME OR %DS_3DLOOK OR %DS_NOFAILCREATE _
            OR %DS_SETFONT OR %WS_SYSMENU OR %WS_THICKFRAME, %WS_EX_LEFT OR %WS_EX_LTRREADING _
            OR %WS_EX_RIGHTSCROLLBAR OR %WS_EX_CONTROLPARENT OR %WS_EX_APPWINDOW, TO hDlg
    
        CONTROL ADD FRAME, hDlg, %IDC_Frame2,   "DA1", 91, 2, 31, 198
        CONTROL ADD LABEL, hDlg, %IDC_Label3,   " 0",96,188,20,8,%WS_CHILD _
                    OR %WS_VISIBLE OR %SS_CENTER, %WS_EX_LEFT OR %WS_EX_LTRREADING
                    
        CONTROL ADD "msctls_trackbar32", hDlg, %IDC_VTrackbar1,"",94,15,25,170,%WS_CHILD _
                    OR %WS_VISIBLE OR %WS_TABSTOP OR %TBS_VERT OR %TBS_LEFT OR %TBS_AUTOTICKS
    
        CONTROL ADD FRAME, hDlg, %IDC_Frame3,   "DA2", 126, 2, 31, 198
        CONTROL ADD LABEL, hDlg, %IDC_Label4,   " 0", 132, 188, 20,8,%WS_CHILD _
                    OR %WS_VISIBLE OR %SS_CENTER, %WS_EX_LEFT OR %WS_EX_LTRREADING
        CONTROL ADD "msctls_trackbar32", hDlg, %IDC_VTrackbar2,"",129,15,25,170,%WS_CHILD _
                    OR %WS_VISIBLE OR %WS_TABSTOP OR %TBS_VERT OR %TBS_LEFT OR %TBS_AUTOTICKS
    
        hFont1 = PBFormsMakeFont("MS Sans Serif",8,700,%FALSE,%FALSE,%FALSE,%ANSI_CHARSET)
    
        
        CONTROL SEND hDlg, %IDC_Label3, %WM_SETFONT, hFont1, 0
        CONTROL SEND hDlg, %IDC_Label4, %WM_SETFONT, hFont1, 0
    
        DIALOG SHOW MODAL hDlg, CALL ShowForm1Proc TO lRslt
    
        CALL DeleteObject(hFont1)
    
        FUNCTION = lRslt
    END FUNCTION
    Best regards
    Jules
    www.rpmarchildon.com

  • #2
    One way is to use minus 255 to 0...

    Code:
    #COMPILE EXE '#win 8.04#
    #DIM ALL
    #INCLUDE "Win32Api.inc" '#2005-01-27#
    #INCLUDE "CommCtrl.inc"
     
    %IDC_Frame1     = 101
    %IDC_Frame2     = 102
    %IDC_VTrackbar1 = 201
    %IDC_VTrackbar2 = 202
    %IDC_Label1     = 301
    %IDC_Label2     = 302
     
    %DAC_MIN_1      = 0
    %DAC_MAX_1      = 255
     
    %DAC_MIN_2      = -255
    %DAC_MAX_2      = 0
    '______________________________________________________________________________
     
    CALLBACK FUNCTION PbProc()
     
     SELECT CASE AS LONG CBMSG
     
       CASE %WM_INITDIALOG
         CONTROL SEND CBHNDL, %IDC_VTrackbar1, %TBM_SETRANGE, %TRUE, MAKDWD(%DAC_MIN_1, %DAC_MAX_1) 'Set range
         CONTROL SEND CBHNDL, %IDC_VTrackbar1, %TBM_SETTICFREQ, 8, 0   'Set tic frequency
         CONTROL SEND CBHNDL, %IDC_VTrackbar1, %TBM_SETPAGESIZE, 0, 10 'Set page size
     
         CONTROL SEND CBHNDL, %IDC_VTrackbar2, %TBM_SETRANGE, %TRUE, MAKLNG(%DAC_MIN_2, %DAC_MAX_2) 'Set range
         CONTROL SEND CBHNDL, %IDC_VTrackbar2, %TBM_SETTICFREQ, 8, 0   'Set tick frequency
         CONTROL SEND CBHNDL, %IDC_VTrackbar2, %TBM_SETPAGESIZE, 0, 10 'Set page size
         CONTROL SEND CBHNDL, %IDC_VTrackbar2, %TBM_SETPOS, %TRUE, %DAC_MIN_2 'Set initial position
     
       CASE %WM_VSCROLL
         'Handle in CBLPARAM, code in LO(WORD, CBWPARAM), position in HI(INTEGER, CBWPARAM)
         SELECT CASE LOWRD(CBWPARAM)
           CASE %TB_THUMBTRACK, %TB_LINEDOWN, %TB_LINEUP, _
                %TB_PAGEDOWN, %TB_PAGEUP, %TB_TOP, %TB_BOTTOM
     
             SELECT CASE GetDlgCtrlID(CBLPARAM) 'Handle in CBLPARAM to id
     
               CASE %IDC_VTrackbar1
                 CONTROL SET TEXT CBHNDL, %IDC_Label1, STR$(HI(INTEGER, CBWPARAM)) 'Update label with position
     
               CASE %IDC_VTrackbar2
                 CONTROL SET TEXT CBHNDL, %IDC_Label2, STR$(ABS(HI(INTEGER, CBWPARAM))) 'Update label with position
     
             END SELECT
         END SELECT
     
     END SELECT
     
    END FUNCTION
    '______________________________________________________________________________
     
    FUNCTION PBMAIN()
     LOCAL hDlg AS DWORD
     
     DIALOG NEW %HWND_DESKTOP, "Trackbar 0 to 255 and 255 to 0", , , 265, 210, _
                %WS_CAPTION OR %WS_MINIMIZEBOX OR %WS_SYSMENU, 0 TO hDlg
     
     CONTROL ADD FRAME, hDlg, %IDC_Frame1, "DA1", 95, 2, 31, 198
     CONTROL ADD "MsCtls_TrackBar32", hDlg, %IDC_VTrackbar1, "", 98, 15, 25, 170, _
                 %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR %TBS_VERT OR %TBS_LEFT OR %TBS_AUTOTICKS
     CONTROL ADD LABEL, hDlg, %IDC_Label1, " 0", 100, 188, 20, 8, _
                 %WS_CHILD OR %WS_VISIBLE OR %SS_CENTER, %WS_EX_LEFT OR %WS_EX_LTRREADING
     
     CONTROL ADD FRAME, hDlg, %IDC_Frame2, "DA2", 160, 2, 31, 198
     CONTROL ADD "MsCtls_TrackBar32", hDlg, %IDC_VTrackbar2, "", 163, 15, 25, 170, _
                 %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR %TBS_VERT OR %TBS_LEFT OR %TBS_AUTOTICKS
     CONTROL ADD LABEL, hDlg, %IDC_Label2, " 0", 166, 188, 20, 8, _
                 %WS_CHILD OR %WS_VISIBLE OR %SS_CENTER, %WS_EX_LEFT OR %WS_EX_LTRREADING
     
     DIALOG SHOW MODAL hDlg, CALL PbProc
     
    END FUNCTION
    '______________________________________________________________________________
    '

    Comment


    • #3
      Hi Pierre,

      Thanks for the response, I decided to go that way, but I thought that in the back of my
      mind, you could create the control in that orientation, but guess not.

      Thx.
      Regards,
      Jules
      Best regards
      Jules
      www.rpmarchildon.com

      Comment


      • #4
        Maybe, maybe not?

        TBS_REVERSED
        Version 5.80.This style bit is used for "reversed" trackbars, where a smaller number indicates "higher" and a larger number indicates "lower." It has no effect on the control; it is simply a label that can be checked to determine whether a trackbar is normal or reversed.
        But converting positions on WM_NOTIFY/TBN_ENDDRAG from 0:255 to 255:0 can't be all that hard, can it?
        Last edited by Michael Mattias; 4 Feb 2008, 08:53 AM.
        Michael Mattias
        Tal Systems (retired)
        Port Washington WI USA
        [email protected]
        http://www.talsystems.com

        Comment


        • #5
          Hi Jules;

          This may do it for you.

          Code:
          #COMPILE EXE
          #DIM ALL
          
          '---Includes...
          #INCLUDE "WIN32API.INC"
          #INCLUDE "COMMCTRL.INC"
          #INCLUDE "PBForms.INC"
          
          '---Constants...
          %IDD_Form1           =  101  'main form
          
          %IDC_VTrackbar1      = 1601
          %IDC_Label3          = 1602
          %IDC_VTrackbar2      = 1603
          %IDC_Label4          = 1604
          
          %IDC_Frame2          = 1801
          %IDC_Frame3          = 1802
          
          %DAC_MAX             = 255
          %DAC_MIN             = 0
          
          '---Delcares...
          DECLARE CALLBACK FUNCTION ShowForm1Proc()
          DECLARE FUNCTION ShowForm1(BYVAL hParent AS DWORD) AS LONG
          
          '------------------------------------------------------------------------------
          '
          '------------------------------------------------------------------------------
          SUB UpdateAnalogOutputStatus(BYVAL hDlg AS DWORD, BYVAL dac1 AS BYTE, BYVAL dac2 AS BYTE)
          
              '-update the position of the  trackbars
              ' not necessary like scrollbars, but caller can set it manually with this call.
              'CONTROL SEND hDlg,%IDC_VTrackbar1,%TBM_SETPOS,%TRUE, (255 - dac1)
              CONTROL SEND hDlg,%IDC_VTrackbar2,%TBM_SETPOS,%TRUE, dac2
          
              '-update the values
              CONTROL SET TEXT hDlg,%IDC_Label3, STR$(dac1)
              CONTROL SET TEXT hDlg,%IDC_Label4, STR$(dac2)
          
          END SUB
          
          '------------------------------------------------------------------------------
          '
          '------------------------------------------------------------------------------
          FUNCTION PBMAIN()
              PBFormsInitComCtls( %ICC_WIN95_CLASSES OR %ICC_DATE_CLASSES OR %ICC_INTERNET_CLASSES ) 'Macro
              CALL ShowForm1(%HWND_DESKTOP)
          END FUNCTION
          
          '------------------------------------------------------------------------------
          '
          '------------------------------------------------------------------------------
          CALLBACK FUNCTION ShowForm1Proc()
              LOCAL lrt AS LONG
              LOCAL cstatus AS STRING
              STATIC cardAddress AS LONG
              LOCAL tPos1 AS LONG, tPos2 AS LONG
              '---
              SELECT CASE AS LONG CBMSG
                  '---
                  CASE %WM_INITDIALOG
                      '-initialize trackbars...
                      CONTROL SEND CBHNDL,%IDC_VTrackbar1,%TBM_SETRANGE,-1,MAKDWD(00,255) 'set range
                      CONTROL SEND CBHNDL,%IDC_VTrackbar1,%TBM_SETPOS, -1, 255
                      CONTROL SEND CBHNDL,%IDC_VTrackbar1,%TBM_SETTICFREQ,8,0   'set tic frequency
                      CONTROL SEND CBHNDL,%IDC_VTrackbar1,%TBM_SETPAGESIZE,0,10 'set page size
          
                      CONTROL SEND CBHNDL,%IDC_VTrackbar2,%TBM_SETRANGE,%TRUE,MAKDWD(0,255) 'set range
                      CONTROL SEND CBHNDL,%IDC_VTrackbar2,%TBM_SETTICFREQ,8,0   'set tick frequency
                      CONTROL SEND CBHNDL,%IDC_VTrackbar2,%TBM_SETPAGESIZE,0,10 'set page size
                      CALL UpdateAnalogOutputStatus(CBHNDL,%DAC_MIN,%DAC_MIN)   'set thumb pos to min
                  '---
                  CASE %WM_NCACTIVATE
                      STATIC hWndSaveFocus AS DWORD
                      IF ISFALSE CBWPARAM THEN
                          hWndSaveFocus = GetFocus()
                      ELSEIF hWndSaveFocus THEN
                          SetFocus(hWndSaveFocus)
                          hWndSaveFocus = 0
                      END IF
                  '---
                  CASE %WM_COMMAND
                      SELECT CASE AS LONG CBCTL
                      END SELECT
                  '---
                  CASE %WM_VSCROLL '-handle both trackbars...
                      SELECT CASE LOWRD(CBWPARAM)
                          CASE %TB_THUMBTRACK, _   '-Mouse
                               %TB_LINEDOWN,   _   '-Keyboard
                               %TB_LINEUP,     _   '-Keyboard
                               %TB_PAGEDOWN,   _   '-Keyboard
                               %TB_PAGEUP,     _   '-Keyboard
                               %TB_TOP,        _   '-Keyboard
                               %TB_BOTTOM          '-Keyboard
                              CONTROL SEND CBHNDL,%IDC_VTrackbar1,%TBM_GETPOS,0,0 TO tPos1
                              CONTROL SEND CBHNDL,%IDC_VTrackbar2,%TBM_GETPOS,0,0 TO tPos2
                              tPos1 = LOWRD(255 - tPos1)
                              tPos2 = LOWRD(tPos2)
                              CALL UpdateAnalogOutputStatus(CBHNDL,tPos1,tPos2)
                      END SELECT
                  '---
                  CASE %WM_DESTROY
                  '---
                  CASE %WM_CLOSE
              END SELECT
          END FUNCTION
          
          '------------------------------------------------------------------------------
          '
          '------------------------------------------------------------------------------
          FUNCTION ShowForm1(BYVAL hParent AS DWORD) AS LONG
          
              LOCAL lRslt  AS LONG
              LOCAL hDlg   AS DWORD
              LOCAL hFont1 AS DWORD
          
              DIALOG NEW hParent, "trackbar behavior, temp...", 131, 82, 406, 211, %WS_POPUP OR _
                  %WS_VISIBLE OR %WS_CLIPSIBLINGS OR %WS_BORDER OR %WS_DLGFRAME OR %DS_3DLOOK OR %DS_NOFAILCREATE _
                  OR %DS_SETFONT OR %WS_SYSMENU OR %WS_THICKFRAME, %WS_EX_LEFT OR %WS_EX_LTRREADING _
                  OR %WS_EX_RIGHTSCROLLBAR OR %WS_EX_CONTROLPARENT OR %WS_EX_APPWINDOW, TO hDlg
          
              CONTROL ADD FRAME, hDlg, %IDC_Frame2,   "DA1", 91, 2, 31, 198
              CONTROL ADD LABEL, hDlg, %IDC_Label3,   " 0",96,188,20,8,%WS_CHILD _
                          OR %WS_VISIBLE OR %SS_CENTER, %WS_EX_LEFT OR %WS_EX_LTRREADING
          
              CONTROL ADD "msctls_trackbar32", hDlg, %IDC_VTrackbar1,"",94,15,25,170,%WS_CHILD _
                          OR %WS_VISIBLE OR %WS_TABSTOP OR %TBS_VERT OR %TBS_LEFT OR %TBS_AUTOTICKS
          
              CONTROL ADD FRAME, hDlg, %IDC_Frame3,   "DA2", 126, 2, 31, 198
              CONTROL ADD LABEL, hDlg, %IDC_Label4,   " 0", 132, 188, 20,8,%WS_CHILD _
                          OR %WS_VISIBLE OR %SS_CENTER, %WS_EX_LEFT OR %WS_EX_LTRREADING
              CONTROL ADD "msctls_trackbar32", hDlg, %IDC_VTrackbar2,"",129,15,25,170,%WS_CHILD _
                          OR %WS_VISIBLE OR %WS_TABSTOP OR %TBS_VERT OR %TBS_LEFT OR %TBS_AUTOTICKS
          
              hFont1 = PBFormsMakeFont("MS Sans Serif",8,700,%FALSE,%FALSE,%FALSE,%ANSI_CHARSET)
          
          
              CONTROL SEND hDlg, %IDC_Label3, %WM_SETFONT, hFont1, 0
              CONTROL SEND hDlg, %IDC_Label4, %WM_SETFONT, hFont1, 0
          
              DIALOG SHOW MODAL hDlg, CALL ShowForm1Proc TO lRslt
          
              CALL DeleteObject(hFont1)
          
              FUNCTION = lRslt
          END FUNCTION

          Comment

          Working...
          X