No announcement yet.

Moving Bar Indicator

  • Filter
  • Time
  • Show
Clear All
new posts

  • Moving Bar Indicator

    I use to make some Gas Bar(like those indicator in audio amp)
    so it go up and down depend on the sound level.
    I do that in VB using shape tool, so I just change the
    length according to the input read in, but how to do it
    in PB, Any simple code? (Please note That I am not asking
    for progress bar, this type only can go one line down.)

  • #2
    The "Static" control is the closest thing the VB Shape control (Rectangle only). Create Static control and then change its length (similiar to what you do in VB) using the appropriate API calls.

    Remember to process the WM_CTRLCOLORSTATIC message to set the color.

    Chris Boss
    Computer Workshop
    Developer of "EZGUI"


    • #3
      I use a psuedo owner-drawn control to do this - a static control is the ideal candidate.

      With DDT, I use a FRAME control (ie, a STATIC control in SDK app's) with the %SS_GRAYFRAME style. I intercept %WM_PAINT messages, where upon I get the DC of the control and do my own drawing on it's client area.

      When I want to update the control, I call InvalidateRect(), followed up by the UpdateWindow() API. You could also use the RedrawWindow() function instead. EIther way, this forces a %WM_PAINT event to occur where the control gets redrawn (updated).

      There are other ways, such as creating your own custom control or just drawing directly on the client area of the dialog or window (using the %WM_PAINT method I mentioned above).

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


      • #4
        Hi Chris and Lance
        Please further elaborate "static"
        Can give some example or code?

        Many thank
        Have a nice day



        • #5
          Aisin --
          this is a sample of own control for DDT.
          You can draw everything.
          Advantage of SDK - you have all events.
             #Compile Exe
             #Register None
             #Include "WIN32API.INC"
             Global hBrushMain As Long
             Function WndProc (ByVal hWnd As Long, ByVal wMsg As Long, _
                               ByVal wParam As Long, ByVal lParam As Long) Export As Long
                Static tRect As Rect, ps As PaintStruct, hBrush As Long
                Static Lg As Long
                Select Case wMsg
                   Case %WM_CREATE
                      hBrush = CreateSolidBrush(%YELLOW): Exit Function
                   Case %WM_USER + 1
                      If Lg < 10 Then Incr Lg
                      InvalidateRect hWnd, ByVal %NULL, %FALSE
                      UpdateWindow hWnd
                      Exit Function
                    Case %WM_USER + 2
                      If Lg > 0 Then Decr Lg
                      InvalidateRect hWnd, ByVal %NULL, %FALSE
                      UpdateWindow hWnd
                      Exit Function
                   Case %WM_PAINT
                      GetClientRect hWnd, tRect
                      BeginPaint hWnd, ps
                      ' Draw what you want
                      FillRect ps.hDC, tRect, hBrushMain
                      tRect.nRight = Lg / 10 * tRect.nRight
                      FillRect ps.hDC, tRect, hBrush
                      EndPaint hWnd, ps
                      Exit Function
                   Case %WM_DESTROY
                      DeleteObject hBrush
                      PostQuitMessage 0
                      Exit Function
                End Select
                Function = DefWindowProc(hWnd, wMsg, wParam, lParam)
             End Function
             CallBack Function DlgMainProc
                Select Case CbMsg
                   Case %WM_INITDIALOG
                      hBrushMain = CreateSolidBrush(Rgb(192, 128, 255))
                   Case %WM_CTLCOLORDLG
                      Function = hBrushMain
                   Case %WM_COMMAND
                      If CbCtl = 101 Then PostMessage GetDlgItem(CbHndl, 201), %WM_USER + 1, 0, 0
                      If CbCtl = 102 Then PostMessage GetDlgItem(CbHndl, 201), %WM_USER + 2, 0, 0
                   Case %WM_DESTROY
                      DeleteObject hBrushMain
                End Select
             End Function
             Function RegisterMyControls As Long
                Local Msg         As tagMsg
                Local wndclass    As WndClassEx
                Local szClassName As Asciiz * 80
                Local hInst       As Long
                hInst             = GetModuleHandle (ByVal 0)
                ' Register Main Window Class
                szClassName            = "MyCtrl"
                wndclass.cbSize        = SizeOf(WndClass)
                wndclass.lpfnWndProc   = CodePtr(WndProc)
                wndclass.hInstance     = hInst
                wndclass.hCursor       = LoadCursor( %NULL, ByVal %IDC_ARROW )
                wndclass.hbrBackground = GetStockObject( %NULL_BRUSH )
                wndclass.lpszClassName = VarPtr( szClassName )
                If IsFalse(RegisterClassEx(wndclass)) Then _
                    RegisterClass ByVal (VarPtr(wndclass) + 4)
             End Function
             Function PbMain () As Long
                Local hDlg As Long
                Dialog New 0, "", ,, 100, 60, %WS_SYSMENU To hDlg
                Control Add Button, hDlg, 101, "+", 5, 5, 40, 14
                Control Add Button, hDlg, 102, "-", 50, 5, 40, 14
                Control Add "MyCtrl", hDlg, 201, "", 5, 25, 85, 10, _
                Dialog Show Modal hDlg, Call DlgMainProc
          End Function


          • #6
            Thank Semen!

            I think I can do a lot of thing base on what you shown me.
            I really benefit from this coding.

            Have a nice day



            • #7
              Semen's code is a nice example of a simple Custom Control being used in a DDT dialog, via the CONTROL ADD "CustomControl" statement.

              Anyone care to take this to a new level, and produce a few more custom controls with dials and other 'visual' controls? How about an animated control? It is quite possible to do this using Semen's code as a building block.

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