Announcement

Collapse
No announcement yet.

Question about this progress bar

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

  • #21
    Thanks Pierre glad to hear I am not alone in seeing this. I don't know a lot about the threads and etc. but thought it probably had to do with how the bar was updated/redrawn. You were right in post #13 about Borje's beautiful progressbars they are absolutely gorgeous. BTW when the green is running there is some white that is running over the green making it look like the way Microsoft UPDATES progressbar looks is that the themes doing that or what. I thought they were doing something special but as it turns out that is just part of the themes bar.

    Comment


    • #22
      Leroy,
      See this example of doing it all in the main for a speedy listview with progressbar here.

      Comment


      • #23
        Jim I don't know what you mean by posting a message to the main from the thread and letting the main do the updates. I don't know exactly how to do that.

        Comment


        • #24
          Leroy,
          This is a start. See postmessage.
          Code:
          FOR index = 0 TO 280
             PostMessage(hProgressbar, %PBM_SETPOS, index, 0)
              IF index MOD 2 = 0 THEN
                  CONTROL SET TEXT hDlg, 1500, FORMAT$(index / 280, "#%"" done""")
              END IF
              SLEEP 20
          NEXT
          Your best bet would be to drop the ProgressBarThread altogether. See ShowAll() routine in the link I provided in post #22. Very fast.

          Comment


          • #25
            On my side, all it does is to make the control flickers a lot. The green delay persist.

            Comment


            • #26
              Leroy,
              This is what I was talking about doing away with the thread and incorporating it all in the main. I switched to DIALOG NEW PIXELS and expanded the Progressbar until it produced 32 segments of equal width. The last segment still looks a bit smaller than the rest. DIALOG DOEVENTS used instead of just sleep. This example briefly stops at 50% done.

              Pierre,
              That was just an example of posting a message to the main from within the thread routine.

              Note:
              The 16th segment can be filled before the count gets to 50%. The segments are either on or off. No partial fill. So if the count is between 46.875% and 50% the segment will be on. I chose to update it when
              index MOD 2 = 0 while the text is updated when index MOD 10 = 0. To have them both updated at the same time then make them both index MOD 10 = 0. If you do that then you will not see a smooth continuous fill of the segments. Some segments could light up very quickly while others could light up at an even rate.

              index MOD 2 = 0 seems to be a good fit for both but the progressbar will still show 50% before the label gets to 50%.

              This design uses a dark background so you can never be confused when it reaches 100%.

              HTML Code:
              [code]
              #COMPILE EXE
              #DIM ALL
              
              
              #INCLUDE ONCE "win32api.inc" '"c:\pbwin10\winapi\win32api.inc"
              '#RESOURCE MANIFEST, 1, "XPTheme.xml"
              %PBS_MARQUEE = &H08
              %button_green  = 101
              %button_red    = 102
              %button_yellow = 103
              
              GLOBAL hDlg,hProgressBar AS LONG
              
              DECLARE FUNCTION SetWindowLongPtrA LIB "User32.dll" ALIAS "SetWindowLongA" _
                  (BYVAL hWnd AS DWORD, BYVAL nIndex AS LONG, BYVAL lNewLong AS LONG) AS LONG
              
              '===============================================================================================
              FUNCTION PBMAIN () AS LONG
                LOCAL pbstyle,mFont AS LONG
                FONT NEW "Courier New",12,1,1,1 TO mFont
                DIALOG NEW PIXELS, %HWND_DESKTOP, "Marquee test",,, 600, 180, %WS_SYSMENU TO hDlg
                DIALOG SET COLOR hDlg, %RGB_NAVY, %RGB_NAVY
                CONTROL ADD PROGRESSBAR, hDlg, 1000, "Test", 9,15,581,30
                CONTROL ADD LABEL, hDlg, 1500,"",9,50,581,15,%SS_CENTER OR %SS_CENTERIMAGE
                CONTROL SET FONT hDlg, 1500, mFont
                CONTROL SET COLOR hDlg, 1500, %RGB_WHITE, %RGB_NAVY
                CONTROL ADD BUTTON, hDlg, %button_green, "Green", 56 + 50,75,80,30 ,%BS_CENTER OR %BS_VCENTER
                CONTROL SET FONT hDlg, %button_green, mFont
                CONTROL ADD BUTTON, hDlg, %button_Red, "Red", 248,75,80,30 ,%BS_CENTER OR %BS_VCENTER
                CONTROL SET FONT hDlg, %button_red, mFont
                CONTROL ADD BUTTON, hDlg, %button_yellow, "Yellow", 440 - 50,75,80,30 ,%BS_CENTER OR %BS_VCENTER
                CONTROL SET FONT hDlg, %button_yellow, mFont
              
                hProgressbar = GetDlgItem(hDlg, 1000)
              
                SendMessage(hProgressbar, %PBM_SETRANGE32, 0, 280)  'MAK(dword,0, 280))
                SendMessage(hProgressbar, %PBM_SETSTEP,  1, 0)
                'SendMessage(hProgressbar, %PBM_SETMARQUEE, %TRUE, 35)
                SendMessage(hProgressbar, %PBM_SETMARQUEE, %TRUE, 0) 'every 30 milliseconds
                SendMessage (hProgressbar, %PBM_SETBKCOLOR, 0, RGB(80, 80, 80))
              
                pbStyle = GetWindowLong(hProgressbar, %GWL_STYLE)
                SetWindowLongPtrA (getDlgItem(hDlg,1000), %GWL_STYLE, pbStyle OR %PBS_MARQUEE)
              
                CONTROL POST hDlg, 1000, %PBM_SETMARQUEE, 0, 0
                DIALOG SHOW MODAL hDlg CALL procPB()
              END FUNCTION
              
              CALLBACK FUNCTION procPB() AS LONG
                  LOCAL i,index AS INTEGER
                  LOCAL pbstyle,mFont,ThreadVar AS LONG
                  LOCAL dwStyle, hThread AS DWORD
                  SELECT CASE CB.MSG
                      CASE %WM_INITDIALOG
              
                      CASE %WM_COMMAND
                         SELECT CASE CB.CTL
                             CASE %button_green
                                 IF CB.CTLMSG = %BN_CLICKED THEN
                                     CALL ShowProgressBar(1)
                                     'THREAD CREATE ProgressBarThread(1) TO hThread
                                     'THREAD CLOSE hThread TO ThreadVar
                                 END IF
                                 FUNCTION = 1
              
                             CASE %button_red
                                 IF CB.CTLMSG = %BN_CLICKED THEN
                                     CALL ShowProgressBar(2)
                                     'THREAD CREATE ProgressBarThread(2) TO hThread
                                     'THREAD CLOSE hThread TO ThreadVar
                                 END IF
                                 FUNCTION = 1
              
                             CASE %button_yellow
                                 IF CB.CTLMSG = %BN_CLICKED THEN
                                     CALL ShowProgressBar(3)
                                     'THREAD CREATE ProgressBarThread(3) TO hThread
                                     'THREAD CLOSE hThread TO ThreadVar
                                 END IF
                                 FUNCTION = 1
              
                         END SELECT
                 END SELECT
              END FUNCTION
              
              'THREAD FUNCTION ProgressBarThread(BYVAL CtrlColor AS DWORD) AS LONG
              
              FUNCTION ShowProgressBar(BYVAL CtrlColor AS DWORD) AS LONG
               LOCAL  dwStyle AS DWORD
               LOCAL  index   AS LONG
              
               CONTROL DISABLE hDlg, %Button_Green
               CONTROL DISABLE hDlg, %Button_Red
               CONTROL DISABLE hDlg, %Button_Yellow
              
               SELECT CASE CtrlColor
                   CASE 1
                       SendMessage (hProgressbar, %PBM_SETPOS, 0, 0)
                       SendMessage (hProgressbar, %PBM_SETBKCOLOR, 0, RGB(80, 80, 80))
                       SendMessage (hProgressbar, %PBM_SETBARCOLOR, 0, RGB(0,255,0))
              
                   CASE 2
                       SendMessage (hProgressbar, %PBM_SETPOS, 0, 0)
                       SendMessage (hProgressbar, %PBM_SETBKCOLOR, 0, RGB(80, 80, 80))
                       SendMessage (hProgressbar, %PBM_SETBARCOLOR, 0, RGB(255,0,0))
              
                   CASE 3
                       SendMessage (hProgressbar, %PBM_SETPOS, 0, 0)
                       SendMessage (hProgressbar, %PBM_SETBKCOLOR, 0, RGB(80, 80, 80))
                       SendMessage (hProgressbar, %PBM_SETBARCOLOR, 0, RGB(255,255,0))
              
               END SELECT
              
               '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 280
                  IF index MOD 2 = 0 THEN
                      PROGRESSBAR SET POS hDlg, 1000, index
                  END IF
                  'SendMessage(hProgressbar, %PBM_SETPOS, index, 0)
              
                  IF index MOD 10 = 0 THEN
                      CONTROL SET TEXT hDlg, 1500, FORMAT$(index / 280, "#%"" done""")
                  END IF
              
                  IF index / 280 = .5 THEN DIALOG DOEVENTS 1000
                  DIALOG DOEVENTS 20
                  'SLEEP 20
               NEXT
              
               'SendMessage(hProgressbar, %PBM_SETPOS, 280, 0)
               'SendMessage(hProgressbar, %PBM_SETSTATE, CtrlColor, 0)
               DIALOG DOEVENTS 2000
               'SLEEP 2000
               CONTROL SET TEXT hDlg, 1500, ""
               SendMessage(hProgressbar, %PBM_SETSTATE, 1, 0)
               SendMessage (hProgressbar, %PBM_SETPOS, 0, 0)
              
               'Set marquee
               'SetWindowLong(hProgressbar, %GWL_STYLE, GetWindowLong(hProgressbar, %GWL_STYLE) OR %PBS_MARQUEE)
               'SendMessage(hProgressbar, %PBM_SETMARQUEE, %TRUE, 35)
              
               CONTROL ENABLE hDlg, %Button_Green
               CONTROL ENABLE hDlg, %Button_Red
               CONTROL ENABLE hDlg, %Button_Yellow
              
              END FUNCTION
              [/code]

              Comment


              • #27
                Jim Fritts:
                Yep that does do away with the lag on the green bar and it fills up at exactly 50% and 100%. I guess it comes down to if you want a themed bar or not themed, I personally like the look of a themed bar but I do realize you can't have but Green, Red or Yellow bars UNLESS you can program like Borje then you can do almost anything you want. I want to thank everyone for all the input it really helps us novice programmers,heck I don't even know if I qualify as a novice programmer.

                Comment


                • #28
                  Originally posted by Jim Fritts View Post
                  Pierre,
                  That was just an example of posting a message to the main from within the thread routine.
                  Hey Jim,
                  Yep, it is not to be picky. I think it's better to avoid confusion for others by saying it did no good in our context.

                  About your last code, for those who don't know, it might also be good to say that unthemed progress bar do not have delay issue.



                  Comment


                  • #29
                    Pierre and Jim:
                    Check this code out not using a thread the GREEN (ONLY THE GREEN) stops before filling the bar, but Percent counter goes to 100%. Both Red and Yellow works fine.


                    #COMPILE EXE
                    #DIM ALL
                    #INCLUDE
                    "c:\pbwin10\winapi\win32api.inc"
                    #RESOURCE MANIFEST, 1, "XPTheme.xml"
                    %PBS_MARQUEE = &H08
                    %button_green
                    = 101
                    %button_red
                    = 102
                    %button_yellow
                    = 103
                    '===============================================================================================
                    FUNCTION PBMAIN () AS LONG
                    LOCAL
                    pbstyle,mFont AS LONG
                    GLOBAL
                    hDlg,hProgressBar AS LONG
                    FONT NEW
                    "Courier New",12,1,1,1 TO mFont
                    DIALOG NEW %HWND_DESKTOP, "Marquee test",,, 300, 100, %WS_SYSMENU TO hDlg
                    DIALOG SET COLOR hDlg, %RGB_NAVY, %RGB_NAVY
                    CONTROL ADD PROGRESSBAR
                    , hDlg, 1000, "Test", 9,15,280,15
                    CONTROL ADD LABEL, hDlg, 1500,"",10,31,280,15,%SS_CENTER OR %SS_CENTERIMAGE
                    CONTROL SET FONT
                    hDlg, 1500, mFont
                    CONTROL ADD LINE, hDlg, -1, "", 148, 9, 1, 22
                    CONTROL SET COLOR hDlg, 1500, %RGB_WHITE, %RGB_NAVY
                    CONTROL ADD BUTTON
                    , hDlg, %button_green, "Green", 70,55,40,15 ,%BS_CENTER OR %BS_VCENTER
                    CONTROL SET FONT
                    hDlg, %button_green, mFont
                    CONTROL ADD BUTTON, hDlg, %button_Red, "Red", 130,55,40,15 ,%BS_CENTER OR %BS_VCENTER
                    CONTROL SET FONT
                    hDlg, %button_red, mFont
                    CONTROL ADD BUTTON, hDlg, %button_yellow, "Yellow", 190,55,40,15 ,%BS_CENTER OR %BS_VCENTER
                    CONTROL SET FONT
                    hDlg, %button_yellow, mFont

                    hProgressbar
                    = GetDlgItem(hDlg, 1000)
                    SendMessage(hProgressbar, %PBM_SETRANGE32, 0, 280) 'MAK(dword,0, 280))
                    SendMessage(hProgressbar, %PBM_SETSTEP, 1, 0)
                    SendMessage(hProgressbar, %PBM_SETMARQUEE, %TRUE, 35)

                    pbStyle = GetWindowLong(hProgressbar, %GWL_STYLE)
                    SetWindowLongPtr (getDlgItem(hDlg,1000), %GWL_STYLE, pbStyle OR %PBS_MARQUEE)

                    CONTROL POST hDlg, 1000, %PBM_SETMARQUEE, 1, 0
                    DIALOG SHOW MODAL hDlg CALL procPB()
                    END FUNCTION

                    CALLBACK FUNCTION
                    procPB()
                    LOCAL i,index AS INTEGER
                    LOCAL
                    pbstyle,mFont,ThreadVar AS LONG
                    LOCAL
                    dwStyle, hThread AS DWORD
                    SELECT CASE CB.MSG
                    CASE %WM_INITDIALOG

                    CASE %WM_COMMAND
                    SELECT CASE CB.CTL
                    CASE
                    %button_green,%button_red,%button_yellow
                    IF CB.CTLMSG = %BN_CLICKED THEN
                    CALL
                    makeBar(BYVAL CBCTL - %Button_Green + 1)

                    END IF
                    END SELECT
                    END SELECT
                    END FUNCTION

                    SUB
                    makeBar(BYVAL CtrlColor AS DWORD)
                    LOCAL dwStyle AS DWORD
                    LOCAL
                    index AS LONG

                    CONTROL DISABLE
                    hDlg, %Button_Green
                    CONTROL DISABLE hDlg, %Button_Red
                    CONTROL DISABLE hDlg, %Button_Yellow

                    '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 280
                    SendMessage
                    (hProgressbar, %PBM_SETPOS, index, 0)
                    IF index MOD 2 = 0 THEN
                    CONTROL SET TEXT
                    hDlg, 1500, FORMAT$(index / 280, "#%"" done""")
                    END IF
                    SLEEP
                    20
                    'IF index = 140 THEN SLEEP 3000
                    NEXT

                    SendMessage(hProgressbar, %PBM_SETPOS, 280, 0)
                    SendMessage(hProgressbar, %PBM_SETSTATE, CtrlColor, 0)
                    SLEEP 3000
                    CONTROL SET TEXT hDlg, 1500, ""
                    SendMessage(hProgressbar, %PBM_SETSTATE, 1, 0)

                    'Set marquee
                    SetWindowLong(hProgressbar, %GWL_STYLE, GetWindowLong(hProgressbar, %GWL_STYLE) OR %PBS_MARQUEE)
                    SendMessage(hProgressbar, %PBM_SETMARQUEE, %TRUE, 35)

                    CONTROL ENABLE hDlg, %Button_Green
                    CONTROL ENABLE hDlg, %Button_Red
                    CONTROL ENABLE hDlg, %Button_Yellow

                    END SUB

                    Comment


                    • #30
                      Hey Leroy,
                      Yep I see, I got "Application stop responding" after a while.
                      The thread used in previous post was to let the dialog breathe,
                      meaning even on heavy task, it could communicate via messages with the OS.

                      With no thread, instead of "SLEEP 20" use "DIALOG DOEVENTS 20" to give dialog a chance to proceed those Windows messages.
                      The result as I see it is in concordance with what have been said before

                      Comment


                      • #31
                        This on Win7 Pro..

                        Click image for larger version  Name:	20200214_191752.gif Views:	0 Size:	157.2 KB ID:	789807?

                        This on Win10 pro ver 1903

                        Click image for larger version  Name:	20200215_145028.gif Views:	0 Size:	361.6 KB ID:	789808?

                        There are some differences in presentation but the delayed synchronization, Bar to Count, is only really apparent on Win10, for my systems.

                        With the code in post #29 I also see that the bar stops and program is reported as 'not responding' (though count also stops at that time).
                        Rgds, Dave

                        Comment


                        • #32
                          Hi Dave,
                          I've tested only on Windows 7, and got a big lag at 50% the bar is about at 30% filled...
                          Anyway, it's not an issue anymore...
                          See next post...

                          Comment


                          • #33
                            Hey Leroy,
                            Googleling, I found a solution to this issue, easy and elegant.
                            A theemed green progress bar have no delay when going backward.
                            So you set it at x + 1, and then at x, making it go backward, hence bypassing the delay.

                            Code:
                             
                            #COMPILE EXE '#Win#
                            #DIM ALL
                            #INCLUDE "Win32Api.inc"
                            #RESOURCE MANIFEST, 1, "XPTheme.xml" 'A manifest is mandatory for a themed progressbar
                            
                            %PBS_MARQUEE  = &H08
                            
                            %Progressbar  = 101
                            %ButtonGreen  = 201
                            %ButtonRed    = 202
                            %ButtonYellow = 203
                            %LabelPerCent = 301
                            
                            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 280
                               'If the progressbar step backwards there is no delay. https://stackoverflow.com/questions/1061715/how-do-i-make-tprogressbar-stop-lagging
                               SendMessage(hProgressbar, %PBM_SETPOS, index + 1, 0)
                               SendMessage(hProgressbar, %PBM_SETPOS, index, 0)
                               CONTROL SET TEXT hDlg, %LabelPerCent, FORMAT$(INT(index / 280 * 100)) & " % done" & " (index is" & STR$(index) & ")"
                               SLEEP 20
                               IF index = 140 THEN SLEEP 1000
                             NEXT
                            
                             SendMessage(hProgressbar, %PBM_SETPOS, 280, 0)
                             SendMessage(hProgressbar, %PBM_SETSTATE, CtrlColor, 0)
                             SLEEP 1000
                             CONTROL SET TEXT hDlg, %LabelPerCent, ""
                             SendMessage(hProgressbar, %PBM_SETSTATE, 1, 0)
                            
                             '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 DWORD
                            
                             SELECT CASE CBMSG
                               CASE %WM_COMMAND
                                 SELECT CASE CBCTL
                                   CASE %ButtonGreen,%ButtonRed,%ButtonYellow
                                     IF CBCTLMSG = %BN_CLICKED 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
                             LOCAL hFont AS DWORD
                            
                             FONT NEW "Courier New", 12, 1, 1, 1 TO hFont
                             DIALOG NEW %HWND_DESKTOP, "ProgressBar color demo",,, 300, 100, %WS_SYSMENU, 0 TO hDlg
                             DIALOG SET COLOR hDlg, %RGB_NAVY, %RGB_NAVY
                            
                             CONTROL ADD "MSCTLS_PROGRESS32", hDlg, %Progressbar, "", 9, 15, 280, 15, _
                             %WS_VISIBLE OR %WS_CHILD OR %PBS_MARQUEE '%PBS_MARQUEE need manifest
                             hProgressbar = GetDlgItem(hDlg, %Progressbar)
                             PostMessage(hProgressbar, %PBM_SETRANGE, 0, MAKDWD(0, 280))
                             PostMessage(hProgressbar, %PBM_SETSTEP,  1, 0)
                            
                             CONTROL ADD LINE, hDlg, -1, "", 148, 4, 1, 8
                            
                             CONTROL ADD LABEL, hDlg, %LabelPerCent,"0%", 10, 30, 280, 15, %SS_CENTER OR %SS_CENTERIMAGE
                             CONTROL SET COLOR hDlg, %LabelPerCent, %RGB_WHITE, %RGB_NAVY
                             CONTROL SET FONT hDlg, %LabelPerCent, hFont
                            
                             CONTROL ADD BUTTON, hDlg, %ButtonGreen, "green", 65, 55, 45, 15, %BS_DEFAULT
                             CONTROL SET FONT hDlg, %ButtonGreen, hFont
                            
                             CONTROL ADD BUTTON, hDlg, %ButtonRed, "red", 130, 55, 40, 15, %BS_DEFAULT
                             CONTROL SET FONT hDlg, %ButtonRed, hFont
                            
                             CONTROL ADD BUTTON, hDlg, %ButtonYellow, "yellow", 190, 55, 55, 15, %BS_DEFAULT
                             CONTROL SET FONT hDlg, %ButtonYellow, hFont
                            
                             hIcon = ExtractIcon(GETMODULEHANDLE(""), "Shell32.dll", 249)
                             SetClassLong(hDlg, %GCL_HICON, hIcon)
                            
                             DIALOG SHOW MODAL hDlg CALL DlgProc
                            
                             FONT END hFont
                             DestroyIcon(hIcon)
                            
                            END FUNCTION
                            '_____________________________________________________________________________
                            '

                            Comment


                            • #34
                              Good sleuthing Pierre!
                              Rgds, Dave

                              Comment


                              • #35
                                Thank you Pierre, indeed this is an excellent progress bar demo

                                Dave, that "Screen Grabber Pro" do look good , what's your review of this program?. I haven't tried it out yet

                                Comment


                                • #36

                                  I found the difference between my Win7 and WIn10 systems.

                                  One (Win7) had an 'Ease of Access Centre' setting "Turn off unnecessary animations" Checked.

                                  Turns out it that setting controls the effect that Leroy noted in post #21..
                                  "..some white that is running over the green making it look like the way Microsoft UPDATES progressbar looks.."

                                  The animation was permitted on the Win10 system. It introduces the delay that sets the Green bar performance apart from the Red and Yellow ones.

                                  Tim,
                                  Just started to play with that Screen Grabber - quite good so far
                                  Rgds, Dave

                                  Comment


                                  • #37
                                    Wow,
                                    That's amazing!

                                    This also appears to work well on my machine thanks to Pierre's insight.
                                    No extra thread used.

                                    HTML Code:
                                    [code]
                                    #COMPILE EXE
                                    #DIM ALL
                                    
                                    'Developed on WIN 10 1909 PBWIN 10.4  Themed or unthemed that is the question
                                    
                                    #INCLUDE ONCE "win32api.inc"
                                    
                                    %UseXPTheme = 1   '(=0) for no theme (=1) for themed dialog
                                    
                                    #IF %UseXPTheme
                                        #RESOURCE MANIFEST, 1, "XPTheme.xml"
                                    #ENDIF
                                    
                                    %PBS_MARQUEE = &H08
                                    %button_green  = 101
                                    %button_red    = 102
                                    %button_yellow = 103
                                    
                                    %ID_BarUpdate  = 1105  'WM_COMMAND function to update the bar and label
                                    
                                    %BarLength      = 599  'overall bar length to get full segments the entire length of the bar
                                    %IndexLimit     = 299  '~one half of bar length
                                    %Progressbar    = 1000 'progress bar ID
                                    
                                    GLOBAL hDlg,hProgressBar AS LONG
                                    
                                    '===============================================================================================
                                    FUNCTION PBMAIN () AS LONG
                                      LOCAL pbstyle,mFont AS LONG
                                      FONT NEW "Courier New",12,1,1,1 TO mFont
                                      DIALOG NEW PIXELS, %HWND_DESKTOP, "Marquee test",,, 620, 180, %WS_SYSMENU TO hDlg
                                      DIALOG SET COLOR hDlg, %RGB_NAVY, %RGB_NAVY
                                    
                                      CONTROL ADD PROGRESSBAR, hDlg, %Progressbar, "", 10,15,%BarLength,30, %PBS_SMOOTH
                                    
                                      CONTROL ADD LABEL, hDlg, 1500,"0% done",10,50,%BarLength,15,%SS_CENTER OR %SS_CENTERIMAGE
                                      CONTROL SET FONT hDlg, 1500, mFont
                                      CONTROL SET COLOR hDlg, 1500, %RGB_WHITE, %RGB_NAVY
                                      CONTROL ADD BUTTON, hDlg, %button_green, "Green", 128,75,80,30 ,%BS_CENTER OR %BS_VCENTER
                                      CONTROL SET FONT hDlg, %button_green, mFont
                                      CONTROL ADD BUTTON, hDlg, %button_Red, "Red", 270,75,80,30 ,%BS_CENTER OR %BS_VCENTER
                                      CONTROL SET FONT hDlg, %button_red, mFont
                                      CONTROL ADD BUTTON, hDlg, %button_yellow, "Yellow", 412,75,80,30 ,%BS_CENTER OR %BS_VCENTER
                                      CONTROL SET FONT hDlg, %button_yellow, mFont
                                    
                                      hProgressbar = GetDlgItem(hDlg, %Progressbar)
                                    
                                      SendMessage(hProgressbar, %PBM_SETRANGE32, 0, %BarLength)
                                      SendMessage(hProgressbar, %PBM_SETSTEP,  1, 0)
                                      SendMessage (hProgressbar, %PBM_SETBKCOLOR, 0, RGB(80, 80, 80))
                                    
                                      DIALOG SHOW MODAL hDlg CALL procPB()
                                    END FUNCTION
                                    
                                    CALLBACK FUNCTION procPB() AS LONG
                                        LOCAL i,index AS INTEGER
                                        LOCAL pbstyle,mFont,ThreadVar AS LONG
                                        LOCAL dwStyle, hThread AS DWORD
                                        LOCAL TLindex AS LONG
                                    
                                        SELECT CASE CB.MSG
                                            CASE %WM_INITDIALOG
                                    
                                            CASE %WM_COMMAND
                                               SELECT CASE CB.CTL
                                                   CASE %button_green
                                                       IF CB.CTLMSG = %BN_CLICKED THEN
                                                           CALL ShowProgressBar(1)
                                                       END IF
                                                       FUNCTION = 1
                                    
                                                   CASE %button_red
                                                       IF CB.CTLMSG = %BN_CLICKED THEN
                                                           CALL ShowProgressBar(2)
                                                       END IF
                                                       FUNCTION = 1
                                    
                                                   CASE %button_yellow
                                                       IF CB.CTLMSG = %BN_CLICKED THEN
                                                           CALL ShowProgressBar(3)
                                                       END IF
                                                       FUNCTION = 1
                                    
                                                   CASE %ID_BarUpdate
                                                       TLindex = LO(WORD, CB.LPARAM)
                                                       'If the progressbar step backwards there is no delay. https://stackoverflow.com/questions/1061715/how-do-i-make-tprogressbar-stop-lagging
                                                       PROGRESSBAR SET POS hDlg, %Progressbar, (TLindex * 2) + 1  'Thanks to Pierre
                                                       PROGRESSBAR SET POS hDlg, %Progressbar, (TLindex * 2)
                                                       CONTROL REDRAW hDlg, %Progressbar
                                                       CONTROL REDRAW hDlg, %Progressbar 'to help limit the animation effects on the green bar
                                                       IF TLindex >= %IndexLimit THEN
                                                           CONTROL SET TEXT hDlg, 1500, FORMAT$(100/100, "#%"" done""")
                                                       ELSE
                                                           CONTROL SET TEXT hDlg, 1500, FORMAT$((TLindex * 2) / %BarLength, "#%"" done""")
                                                       END IF
                                                       FUNCTION = 1
                                    
                                    
                                               END SELECT
                                       END SELECT
                                    END FUNCTION
                                    
                                    
                                    FUNCTION ShowProgressBar(BYVAL CtrlColor AS DWORD) AS LONG
                                     LOCAL  dwStyle AS DWORD
                                     LOCAL  index   AS LONG
                                    
                                     CONTROL DISABLE hDlg, %Button_Green
                                     CONTROL DISABLE hDlg, %Button_Red
                                     CONTROL DISABLE hDlg, %Button_Yellow
                                    
                                     CONTROL REDRAW hDlg, %Button_Green
                                     CONTROL REDRAW hDlg, %Button_Red
                                     CONTROL REDRAW hDlg, %Button_Yellow
                                    
                                     DIALOG DOEVENTS 20
                                    
                                     SendMessage (hProgressbar, %PBM_SETPOS, 0, 0)
                                     SendMessage (hProgressbar, %PBM_SETBKCOLOR, 0, RGB(80, 80, 80))
                                    
                                     SELECT CASE CtrlColor
                                         CASE 1
                                             SendMessage (hProgressbar, %PBM_SETBARCOLOR, 0, RGB(0,255,0))  'GREEN
                                    
                                         CASE 2
                                             SendMessage (hProgressbar, %PBM_SETBARCOLOR, 0, RGB(255,0,0))  'RED
                                    
                                         CASE 3
                                             SendMessage (hProgressbar, %PBM_SETBARCOLOR, 0, RGB(255,255,0))'YELLOW
                                    
                                     END SELECT
                                    
                                     'PBST_NORMAL = green = 1, PBST_ERROR = red = 2, PBST_PAUSED = yellow = 3.
                                     SendMessage(hProgressbar, %PBM_SETSTATE, CtrlColor, 0)
                                    
                                     FOR index = 0 TO 150    'half the bar
                                         SendMessage hDlg, %WM_COMMAND, %ID_BarUpdate, index
                                         SLEEP 10
                                         DIALOG DOEVENTS 20
                                     NEXT
                                    
                                     SLEEP 2000
                                     DIALOG DOEVENTS 20
                                    
                                     FOR index = 151 TO %IndexLimit + 1  'the other half of the bar
                                         SendMessage hDlg, %WM_COMMAND, %ID_BarUpdate, index
                                         SLEEP 10
                                         DIALOG DOEVENTS 20
                                     NEXT
                                    
                                     SLEEP 2000
                                     DIALOG DOEVENTS 20
                                     CONTROL SET TEXT hDlg, 1500, ""
                                     SendMessage hDlg, %WM_COMMAND, %ID_BarUpdate, 0
                                     CONTROL REDRAW hDlg, %Progressbar
                                    
                                     CONTROL ENABLE hDlg, %Button_Green
                                     CONTROL ENABLE hDlg, %Button_Red
                                     CONTROL ENABLE hDlg, %Button_Yellow
                                    
                                     CONTROL REDRAW hDlg, %Button_Green
                                     CONTROL REDRAW hDlg, %Button_Red
                                     CONTROL REDRAW hDlg, %Button_Yellow
                                     DIALOG DOEVENTS 20
                                    
                                    
                                    END FUNCTION
                                    [/code]
                                    Last edited by Jim Fritts; 15 Feb 2020, 11:45 AM.

                                    Comment


                                    • #38
                                      Many thanks fellows, and GREAT WORK Pierre, That does stop the lagging but adds just a tiny flicker to the bar. I have learned soooo much about progress bars from this discussion and will be forever indebted to all of you for your help.

                                      Comment


                                      • #39
                                        Pierre:
                                        I read the article on progressbar lag on the stackoverflow.com. That was a very very interesting article and it answered my question about the "moving highlight" on the green bar.

                                        Thank you so very much.

                                        Comment


                                        • #40
                                          Slightly less flicker:

                                          Code:
                                              SendMessage(hProgressbar, %PBM_SETPOS, index, 0)
                                              SendMessage(hProgressbar, %PBM_SETPOS, index - 1, 0)
                                              SendMessage(hProgressbar, %PBM_SETPOS, index, 0)
                                          Rgds, Dave

                                          Comment

                                          Working...
                                          X