Announcement

Collapse
No announcement yet.

Anyone know how to do a "Marquee" style progress bar?

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

  • #21
    Peter,

    Very nice. Excellent example of making good use of SDK and DDT together and how DDT makes programing much simpler and quicker.

    Comment


    • #22
      I agree Stuart!

      Comment


      • #23
        Originally posted by Peter Lameijn View Post
        Microsoft decided that one color is enough: only green allowed in new style...
        Peter, if I may...

        Click image for larger version  Name:	ProgressBar.png Views:	56 Size:	12.2 KB ID:	787758

        Code:
        #COMPILE EXE '#Win#
        #INCLUDE "Win32Api.inc"
        #INCLUDE "CommCtrl.inc"
        #RESOURCE MANIFEST, 1, "xpTheme.xml" 'Common control 6 manifest needed
        '#RESOURCE "x.pbr"
        
        %ButtonGreen  = 101
        %ButtonRed    = 102
        %ButtonYellow = 103
        %Progressbar  = 201
        
        %PBS_MARQUEE  = &H08???
        
        GLOBAL hDlg         AS DWORD
        GLOBAL hProgressbar AS DWORD
        '_____________________________________________________________________________
        
        THREAD FUNCTION ProgressBarThread(BYVAL CtrlColor AS DWORD) AS LONG
         LOCAL  dwStyle AS DWORD
         LOCAL  index   AS LONG
        
         CONTROL DISABLE hDlg, %ButtonGreen
         CONTROL DISABLE hDlg, %ButtonRed
         CONTROL DISABLE hDlg, %ButtonYellow
        
         'Remove marquee
         dwStyle = GetWindowLong(hProgressbar, %GWL_STYLE)
         IF (dwStyle AND %PBS_MARQUEE) THEN
           SendMessage(hProgressbar, %PBM_SETMARQUEE, %FALSE, 0)
           SetWindowLong(hProgressbar, %GWL_STYLE, dwStyle - %PBS_MARQUEE)
         END IF
        
         'PBST_NORMAL = green = 1, PBST_ERROR = red = 2, PBST_PAUSED = yellow = 3.
         SendMessage(hProgressbar, %PBM_SETSTATE, CtrlColor, 0)
         FOR index = 0 TO 100
           SendMessage(hProgressbar, %PBM_SETPOS, index, 0)
           SLEEP 30
         NEXT
         SendMessage(hProgressbar, %PBM_SETPOS, 100, 0)
         SendMessage(hProgressbar, %PBM_SETSTATE, CtrlColor, 0)
         SLEEP 1000
        
         'Set marquee
         SetWindowLong(hProgressbar, %GWL_STYLE, GetWindowLong(hProgressbar, %GWL_STYLE) OR %PBS_MARQUEE)
         SendMessage(hProgressbar, %PBM_SETMARQUEE, %TRUE, 35)
        
         CONTROL ENABLE hDlg, %ButtonGreen
         CONTROL ENABLE hDlg, %ButtonRed
         CONTROL ENABLE hDlg, %ButtonYellow
        
        END FUNCTION
        '_____________________________________________________________________________
        
        CALLBACK FUNCTION DlgProc
         LOCAL  hThread   AS DWORD
         LOCAL  ThreadVar    AS LONG
        
         SELECT CASE CBMSG
           CASE %WM_COMMAND
             SELECT CASE LOWRD(CBWPARAM)
               CASE %ButtonGreen, %ButtonYellow, %ButtonRed
                 IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                   'PBST_NORMAL = green = 1, PBST_ERROR = red = 2, PBST_PAUSED = yellow = 3.
                   THREAD CREATE ProgressBarThread(BYVAL CBCTL - %ButtonGreen + 1) TO hThread
                   THREAD CLOSE hThread TO ThreadVar
                 END IF
             END SELECT
         END SELECT
        
        END FUNCTION
        '_____________________________________________________________________________
        
        FUNCTION PBMAIN () AS LONG
         LOCAL hIcon AS DWORD
        
         DIALOG NEW %HWND_DESKTOP, "ProgressBar marquee & color",,, 160, 90, %WS_SYSMENU, 0 TO hDlg
        
         CONTROL ADD BUTTON, hDlg, %ButtonGreen,  "green",   10, 52, 40, 14
         CONTROL ADD BUTTON, hDlg, %ButtonRed,    "red",     60, 52, 40, 14
         CONTROL ADD BUTTON, hDlg, %ButtonYellow, "yellow", 110, 52, 40, 14
        
         CONTROL ADD "MSCTLS_PROGRESS32", hDlg, %Progressbar, "", 22, 22, 108, 16, _
         %WS_VISIBLE OR %WS_CHILD OR %PBS_MARQUEE
         hProgressbar = GetDlgItem(hDlg, %Progressbar)
         SendMessage(hProgressbar, %PBM_SETRANGE, 0, MAKDWD(0, 100))
         SendMessage(hProgressbar, %PBM_SETSTEP,  1, 0)
         SendMessage(hProgressbar, %PBM_SETMARQUEE, %TRUE, 35)
        
         hIcon = ExtractIcon(GetModuleHandle(""), "Shell32.dll", 249)
         SetClassLong(hDlg, %GCL_HICON, hIcon)
        
         DIALOG SHOW MODAL hDlg CALL DlgProc
        
         DestroyIcon(hIcon)
        
        END FUNCTION
        '_____________________________________________________________________________
        '
        Last edited by Pierre Bellisle; 25 Dec 2019, 10:48 PM.

        Comment


        • #24
          Stuart/David!

          While good code, you've cheered too soon. The use of any API was unnecessary. Here's the same code, no API needed ...

          Code:
          #Compile Exe "test.exe"
          #Dim All
          #Include "win32api.inc"
          #Resource Manifest, 1, "XPTheme.xml"
          '===============================================================================================
          Function PBMain () As Long
          Local hdlg,pbstyle As Long
            Dialog New %HWND_Desktop, "Marquee test",,, 200, 60, %WS_SysMenu To hDlg
            Control Add Progressbar, hDlg, 1000, "Test", 10,15,180,15, %PBS_Marquee
            Control Post hDlg, 1000, %PBM_SETMARQUEE, 1, 0
            Dialog Show Modal hDlg
          End Function
          And besides. the code example did not use CreateWindow, which is my minimal requirement for code to be considered SDK programming.

          ... added ... Peter, no offense intended, just making a point to Stuart/David.

          Comment


          • #25
            Nice one Gary!
            Guess this old dog learned some new tricks today.
            Last edited by David Clarke; 25 Dec 2019, 07:29 AM.

            Comment


            • #26
              Originally posted by Gary Beene View Post
              And besides. the code example did not use CreateWindow, which is my minimal requirement for code to be considered SDK programming.
              .
              And therein lies the crux of the whole DDT/SDK debate. Too any people think the same way.

              Apparently if you always use one particular SDK function to create your primary user interface you are an elite 'SDK programmer".
              However, you are just a [insert your choice of denigrating expression here] if you use the dialog wrappers that Bob developed.no matter how any thousands of other SDK functions you use in for the rest of your application.
              I'm sick and tired of this debate and of the superior attitude displayed by the DDT detractors.

              Comment


              • #27
                @Gary: Yes, that works too!

                With undocumented styles in PB I always use Get/SetWindowlong, because it preserves the existing styles for the control.
                Code:
                 Control Add Progressbar, hDlg, 1000, "Test", 10,15,180,15, %PBS_Marquee
                will remove the default styles for the control (if any are set). Only %PBS_MARQUEE will be set.

                Would have been nice if control creation had a possibility to add a style to the default styles.
                For instance by starting with a or:


                Code:
                 Control Add Progressbar, hDlg, 1000, "test", 10, 15, 180, 15, OR %PBS_MARQUEE
                Regards,
                Peter

                Comment


                • #28
                  Brilliant Pierre, a very cool program

                  Comment


                  • #29
                    will remove the default styles for the control (if any are set). Only %PBS_MARQUEE will be set.
                    True, or the defaults you want to retain can be included with the additional style. For most controls they are bold in help. In this case the default style %WS_BORDER is stated in the text of help. Keeping default and adding marquee would be
                    Code:
                    Control Add Progressbar, hDlg, 1000, "Test", 10,15,180,15, %WS_Border OR %PBS_Marquee, 0
                    Cheers,
                    Dale

                    Comment


                    • #30
                      I am lazy...

                      If I use get/setwindowlong, I don't have to look up the default styles in the helpfile...
                      Regards,
                      Peter

                      Comment


                      • #31
                        Anybody know how the "new style", where the moving part is faded on the leading and trailing edges, is done?

                        Comment


                        • #32
                          Now I am thinking that may be an AERO them thing.

                          Comment


                          • #33
                            That animation is a thing of Common Controls V6 and up...
                            Regards,
                            Peter

                            Comment


                            • #34
                              Originally posted by Peter Lameijn View Post
                              That animation is a thing of Common Controls V6 and up...
                              So it may not work in older systems, like a non-updated installation of XP and back. Probably not a big problem today, but could end up being at some places and a reason why to use code that also works without themes. Or at least check comctl32.dll version and insert backup code for systems without v6 or later. I never had any support problem using animation or simple moving text like "please wait"..

                              MS says: "Because various versions of ComCtl32.dll were distributed with Internet Explorer, the version that is active is sometimes different from the version that was shipped with the operating system. Therefore, your application must directly determine which version of ComCtl32.dll is present."

                              Comment


                              • #35
                                Originally posted by Borje Hagsten View Post

                                So it may not work in older systems, like a non-updated installation of XP and back. Probably not a big problem today, but could end up being at some places and a reason why to use code that also works without themes. Or at least check comctl32.dll version and insert backup code for systems without v6 or later. I never had any support problem using animation or simple moving text like "please wait"..

                                MS says: "Because various versions of ComCtl32.dll were distributed with Internet Explorer, the version that is active is sometimes different from the version that was shipped with the operating system. Therefore, your application must directly determine which version of ComCtl32.dll is present."
                                You can still use a GRAPHIC control and a bitmap.
                                The bitmap would have the transitional color bar in its center.
                                You would select the portion to be displayed using a counter.
                                I'll work up an example.
                                Like this one:
                                Code:
                                #COMPILE EXE
                                #DIM ALL
                                #DEBUG DISPLAY ON
                                #INCLUDE "win32api.inc"
                                
                                TYPE bgra
                                    b AS BYTE
                                    g AS BYTE
                                    r AS BYTE
                                    a AS BYTE
                                END TYPE
                                
                                ENUM ctrls SINGULAR
                                    progbar00 = 500
                                    progbar01
                                    progbar02
                                    progbar03
                                    progtmr
                                END ENUM
                                
                                FUNCTION PBMAIN () AS LONG
                                    LOCAL hWin, xitcode AS LONG
                                    RANDOMIZE
                                    DIALOG NEW PIXELS, 0, "Marquee Progress", , , 400, 130, %WS_BORDER OR %WS_CAPTION OR %WS_SYSMENU TO hWin
                                    DIALOG SET COLOR hWin, %WHITE, %GRAY
                                    CONTROL ADD GRAPHIC, hWin, %progbar00, "", 5, 5, 256, 20
                                    CONTROL ADD GRAPHIC, hWin, %progbar01, "", 5, 30, 130, 20
                                    CONTROL ADD GRAPHIC, hWin, %progbar02, "", 5, 55, 390, 10
                                    CONTROL ADD GRAPHIC, hWin, %progbar03, "", 5, 70, 300, 54
                                    DIALOG SHOW MODAL hWin, CALL dlgproc() TO xitcode
                                    FUNCTION = xitcode
                                END FUNCTION
                                
                                CALLBACK FUNCTION dlgproc()
                                    LOCAL getvalue, destbmp, srcbmp AS STRING, wgt, itr AS LONG, temph AS DWORD
                                    SELECT CASE CB.MSG
                                        CASE %WM_INITDIALOG
                                            drawbargraphic CB.HNDL, %progbar00
                                            settimer(CB.HNDL, %progtmr, 10, 0)
                                        CASE %WM_TIMER
                                            updateprogressbar CB.HNDL, %progbar01
                                            updateprogressbar CB.HNDL, %progbar02
                                            updateprogressbar CB.HNDL, %progbar03
                                        CASE %WM_DESTROY
                                            killtimer(CB.HNDL, %progtmr)
                                    END SELECT
                                END FUNCTION
                                
                                ' Draw a gradient progress bar. You can use any bitmap resource or graphic object.
                                SUB drawbargraphic(dlg AS DWORD, ctl AS LONG)
                                    LOCAL x, y AS LONG, buf, tmp AS STRING, pxls(), pblr() AS bgra
                                    GRAPHIC ATTACH dlg, ctl
                                    GRAPHIC COLOR %RED, %WHITE
                                    GRAPHIC CLEAR
                                    FOR x = 0 TO 9
                                        y = x \ 2
                                        GRAPHIC BOX (100 + x, y)-(155-x, 19-y), 50, RGB(220-x*20, 250, 220-x*20), RGB(220-x*20, 250, 220-x*20)
                                    NEXT
                                    GRAPHIC LINE (109, 5)-(145, 5), RGB(70, 255, 40)
                                END SUB
                                
                                ' Update progress bar. Automatically keeps track of position using a CONTROL USER value.
                                SUB updateprogressbar(dlg AS DWORD, ctl AS LONG)
                                    LOCAL x, y, progpoint AS LONG
                                    CONTROL GET USER dlg, ctl, 1 TO progpoint
                                    progpoint = (progpoint + 2) MOD(155)
                                    CONTROL SET USER dlg, ctl, 1, progpoint
                                    CONTROL GET SIZE dlg, ctl TO x, y
                                    GRAPHIC ATTACH dlg, ctl, REDRAW
                                    GRAPHIC STRETCH dlg, %progbar00, (155-progpoint, 0)-(255-progpoint, 19) TO (0, 0)-(x, y), 0, %HALFTONE
                                    GRAPHIC REDRAW
                                END SUB
                                Last edited by Kurt Kuzba; 26 Dec 2019, 12:10 PM.
                                The world is strange and wonderful.*
                                I reserve the right to be horrifically wrong.
                                Please maintain a safe following distance.
                                *wonderful sold separately.

                                Comment

                                Working...
                                X