Announcement

Collapse
No announcement yet.

Simple Splash Screen

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

  • Simple Splash Screen

    With all of the gbXX apps I've posted here, I don't think I've ever used a splash screen! How can that be?

    Tonight I was working on an app that takes about 5 seconds to initialize and I wanted a simple "Please wait ..." message to appear immediately so the user will know they really did double-click on the start icon and not panic!

    So I came up with this. The splash window will stay visible until the main dialog initialization steps (in %WM_InitDialog) are completed. It seems to work ok.

    Code:
    'Compilable Example:
    #Compile Exe
    #Dim All
    %Unicode = 1
    #Include "Win32API.inc"
    
    %IDC_Graphic = 500
    
    Global hDlg, hFont, hSplash As Dword
    
    Function PBMain() As Long
       'Splash Dialog
       Dialog New Pixels, 0, "Splash",,,750,200, %WS_Popup Or %WS_Border To hSplash
       Control Add Graphic, hSplash, %IDC_Graphic, "", 0,0,750,200
       Font New "Tahoma", 72, 1 To hFont
       Graphic Set Font hFont
       Graphic Set Pos (50,30) : Graphic Print "Please Wait ..."
       Dialog Show Modeless hSplash
    
       'Main Dialog
       Dialog New Pixels, 0, "Main Dialog",,,600,600, %WS_OverlappedWindow To hDlg
       Dialog Show Modal hDlg Call DlgProc
    End Function
    
    CallBack Function DlgProc() As Long
       Select Case Cb.Msg
          Case %WM_InitDialog
             Sleep 5000 'do some initialization stuff
             Dialog End hSplash
       End Select
    End Function

  • #2
    Yes, have done a few of those over the years. 5 seconds can feel like a life time in stressed computer world, so can be nice with something to look at too, like a status bar or if loading time is hard to calculate/follow, a SysAnimate32 control or simply print some constantly updated text about load status. Added an old statusbar test code I found with a SplashProc to your code just for fun.
    Code:
    'Compilable Example:
    #COMPILE EXE
    #DIM ALL
    %Unicode = 1
    #INCLUDE "Win32API.inc"
    
    %IDC_Graphic     = 500
    %IDC_Progressbar = 510
    %ID_Timer        = 600
    
    GLOBAL hDlg, hFont, hSplash AS DWORD
    
    '--------------------------------------------------------------------
    FUNCTION PBMAIN() AS LONG
       'Splash Dialog
       DIALOG NEW PIXELS, 0, "Splash",,,750,200, %WS_Popup OR %WS_Border TO hSplash
       CONTROL ADD GRAPHIC, hSplash, %IDC_Graphic, "", 0,0,750,180
       FONT NEW "Tahoma", 72, 1 TO hFont
       GRAPHIC SET FONT hFont
       GRAPHIC SET POS (50,30) : GRAPHIC PRINT "Please Wait ..."
    
       '-----------------------------------------------------------------
       CONTROL ADD PROGRESSBAR, hSplash, %IDC_Progressbar, "", 0, 180, 750, 20, _
                 %WS_CHILD OR %WS_VISIBLE, %WS_EX_STATICEDGE
       PROGRESSBAR SET RANGE hSplash, %IDC_Progressbar, 0, 100
       PROGRESSBAR SET STEP hSplash, %IDC_Progressbar, 1
       '-----------------------------------------------------------------
    
       DIALOG SHOW MODAL hSplash CALL SplashProc  '< made it modal with a SplashProc
    
       'Main Dialog
       DIALOG NEW PIXELS, 0, "Main Dialog",,,600,600, %WS_OverlappedWindow TO hDlg
       DIALOG SHOW MODAL hDlg CALL DlgProc
    END FUNCTION
    
    '--------------------------------------------------------------------
    CALLBACK FUNCTION SplashProc() AS LONG
       LOCAL iPos AS LONG
       STATIC hCur AS DWORD
    
       SELECT CASE CB.MSG
       CASE %WM_InitDialog
           hCur = LoadCursor(0, BYVAL %IDC_APPSTARTING)
           SetTimer CB.HNDL, %ID_Timer, 50, 0  ' to tick 100 times in 5 sec.
    
       CASE %WM_Destroy
           KillTimer CB.HNDL, %ID_Timer
    
       CASE %WM_SetCursor
          IF GetCursor <> hCur THEN SetCursor hCur
          FUNCTION = 1
    
       CASE %WM_Timer
           ' good place too check starting status..
           SLEEP 0
           CONTROL SEND CB.HNDL, %IDC_PROGRESSBAR, %PBM_GETPOS, 0, 0 TO iPos
           PROGRESSBAR STEP CB.HNDL, %IDC_PROGRESSBAR
           IF iPos = 100 THEN DIALOG END CB.HNDL
    
       END SELECT
    END FUNCTION
    '--------------------------------------------------------------------
    
    CALLBACK FUNCTION DlgProc() AS LONG
       SELECT CASE CB.MSG
          CASE %WM_InitDialog
       END SELECT
    END FUNCTION

    Comment


    • #3
      BTW, a mistake I once made was to make the splash screen "Always on top", which resulted in some angry users telling me it covered important processes in other programs. Quickly learned that lesson..

      Comment


      • #4
        Good morning, Borje!

        Yes, the animation is nice. These days, I deal mostly with users who have vision impairments so I tend to avoid animations because they are hard for my users to focus on. However, a simple progress bar such as you suggest should be acceptable even for that user group.

        An animated spinner might be good as well. Since the startup time is approximate, a spinner can just sit there and spin whereas with the progress bar I'd have to code the progress bar to make it a continuous animation that is not dependent on an exact time (but really, just a one-line thing).

        Comment


        • #5
          > With all of the gbXX apps I've posted here, I don't think I've ever used a splash screen! How can that be?
          It can't.

          https://forum.powerbasic.com/forum/u...-screen-wanted

          Code:
          goggle
          site:powerbasic.com splash
          https://duckduckgo.com instead of google

          Comment


          • #6
            Hey Mike!

            Oh no! Busted!

            Comment


            • #7

              Dialog Post CB.Hndl, %WM_User+500, 0, 0
              https://forum.powerbasic.com/forum/u...tdialog-finish
              https://duckduckgo.com instead of google

              Comment


              • #8
                Good morning, Mike!

                Yes, apparently I've dabbled in splash screens more than I thought. My gbXX apps may not use splash screens but I have posted some misc code on the topic.

                A problem with what I posted there is where the GUI requires the initialization steps to form a correct opening-GUI content. In such cases, a splash screen would seem more appropriate.

                Comment


                • #9
                  Originally posted by Gary Beene View Post
                  An animated spinner might be good as well. Since the startup time is approximate, a spinner can just sit there and spin whereas with the progress bar I'd have to code the progress bar to make it a continuous animation that is not dependent on an exact time (but really, just a one-line thing).
                  THIS tweaks me to no end (not you "far better GB"... just the general practice some use). It drives me NUTZ when people use a progress bar to indicate a delay and the bar keeps resetting. The point of a progress bar is to approximate how much of something is done. Microsoft and other companies use the progress bar and keep resetting it over and over again and the user has no clue how much of X is complete. If you want to show "busy" then use a spinner and update some text to say what is going on. Some "spinners" even look like progress bars (BAD concept), a spinner should be something that starts and ends at the same spot (i.e. circle of pie slices, dots, or gradient worm.... or a quartered or 9 box square, etc.), not a line that the when the end is reached it clears and redraws or reverses (something akin to a Cylon eye or KITTs scanner).

                  Heck, even the dual progress bar some use is not a good solution in my opinion (one for current process, one for overall process) as it can be confusing which is which. especially when the current process is a long one.
                  <b>George W. Bleck</b>
                  <img src='http://www.blecktech.com/myemail.gif'>

                  Comment


                  • #10
                    Hi George!

                    Yes, I would agree with you. When the progress bar repeats, you never know how close to being done the app is. Better than nothing but we can do better. I promise not to use that!

                    Comment


                    • #11
                      Hi All

                      Anyone got some splash screen codes using OpenGL that can share with us? OpenGL graphics are quite interesting and elegant for use in a Splash screen

                      Comment


                      • #12
                        Here is an old one from 2008
                        http://www.jose.it-berater.org/smffo....0;attach=8181

                        more there
                        http://www.zapsolution.com/DW/US/gcorner.html

                        or there
                        http://www.objreader.com/index.php?board=5.0
                        Patrice Terrier
                        www.zapsolution.com
                        www.objreader.com
                        Addons: GDImage.DLL 32/64-bit (Graphic library), WinLIFT.DLL 32/64-bit (Skin Engine).

                        Comment


                        • #13
                          Whew Patrice !
                          Unbelievable that your PB programs can achieve such perfections

                          Comment

                          Working...
                          X