dcsimg
Results 1 to 10 of 10

Thread: [RESOLVED] Spinner in VB6

  1. #1

    Thread Starter
    Hyperactive Member Daniel Duta's Avatar
    Join Date
    Feb 2011
    Location
    Bucharest, Romania
    Posts
    302

    Resolved [RESOLVED] Spinner in VB6

    Hi all,
    Could anybody give me a hint if is it possible to create a transparent form for an animated GIF so that to replace a progress bar? I have seen many times these spinners used in applications but I have never seen anything similar done in vb6. Thanks.
    "VB code is practically pseudocode" - Tanner Helland
    "When you do things right, people won't be sure you've done anything at all" - Reed Kimble

  2. #2
    Frenzied Member
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    1,161

    Re: Spinner in VB6

    Here's one I made a few years back using vbRichClient5 if you aren't against using it:

    http://www.vbforums.com/showthread.p...-vbRichClient5

  3. #3
    Fanatic Member
    Join Date
    Dec 2014
    Posts
    724

    Re: Spinner in VB6

    using this
    Code:
    SetWindowLong hWnd, GWL_EXSTYLE, GetWindowLong(hWnd, GWL_EXSTYLE) Or WS_EX_LAYERED
    SetLayeredWindowAttributes hWnd, COLORREF, bAlpha, LWA_COLORKEY
    to make the form transparent, use a color that is not used in the spinner, usually a strong color like cyan.
    after that its easy to just add a timer that will draw the spinner. gif is not needed.

  4. #4

    Thread Starter
    Hyperactive Member Daniel Duta's Avatar
    Join Date
    Feb 2011
    Location
    Bucharest, Romania
    Posts
    302

    Re: Spinner in VB6

    Quote Originally Posted by jpbro View Post
    Here's one I made a few years back using vbRichClient5 if you aren't against using it:

    http://www.vbforums.com/showthread.p...-vbRichClient5
    Thanks, jpbro. I have nothing against RC5 but for this small feature I should include the dll in the setup package. Interesting, it has possibility to create the spinning effect without any GIF image but my concern is related to its transparency. When it is running in a Form it seems to remain backside of other controls from Form instead front side. Also, until now I didn't find the XY coordinates for moving the spinner at a certain position in the Form.
    Name:  Capture.JPG
Views: 109
Size:  12.8 KB
    "VB code is practically pseudocode" - Tanner Helland
    "When you do things right, people won't be sure you've done anything at all" - Reed Kimble

  5. #5
    PowerPoster
    Join Date
    Jun 2013
    Posts
    3,951

    Re: Spinner in VB6

    Quote Originally Posted by Daniel Duta View Post
    When it is running in a Form it seems to remain backside of other controls from Form instead front side.
    You can create Alpha-Popup-Windows (via the RC5-cWidgetForm type) - e.g. wrapped up in a small HostClass
    (I prefix the name of such Classes, which wrap a cWidgetForm with 'cf' - e.g. this one: cfSpinner)
    Code:
    Option Explicit
    
    Private WithEvents mPopUp As cWidgetForm, WithEvents mSpinner As CSpinner
    
    Private Sub Class_Initialize()
      Set mSpinner = New CSpinner
          mSpinner.Size = 180
          mSpinner.SpinDelay = 30
          mSpinner.SpinInDelay = 15
          mSpinner.SpinOutDelay = 25
          mSpinner.RotateClockwise = True
          mSpinner.HolePercent = 80
          mSpinner.Padding = 5
          mSpinner.SegmentCount = 32
          mSpinner.SpinnerDegrees = 320
          mSpinner.SpinRotationDegrees = 12
          mSpinner.SpinInRotationDegrees = 10
          mSpinner.SpinOutRotationDegrees = 18
          mSpinner.BlurAmount = 0
          mSpinner.SpinnerColor = 12616736
          mSpinner.SegmentMargin = 2
          mSpinner.ClipBlurredEdges = False
          mSpinner.FadeInOut = True
          mSpinner.FadeSegments = True
          mSpinner.ZoomInOut = False
    End Sub
    
    Public Property Get Spinner() As CSpinner 'expose the Spinner-Obj, so that one can set its Properties outside
      Set Spinner = mSpinner
    End Property
    
    Public Sub StartSpinning(ParentHwnd As Long, Optional ByVal x&, Optional ByVal y&)
      mSpinner.StartSpinner
      Set mPopUp = Cairo.WidgetForms.CreateChild(ParentHwnd, True, False)
          mPopUp.Move 0, 0, mSpinner.Size, mSpinner.Size
          mPopUp.WidgetRoot.ImageKeyRenderBehaviour = ImgKeyRenderLeft
      If x <> 0 Or y <> 0 Then mPopUp.Move x, y Else mPopUp.CenterOn New_c.Displays(1)
      mPopUp.Show
    End Sub
    
    Public Sub StopSpinning()
      mSpinner.StopSpinner
      If Not mPopUp Is Nothing Then mPopUp.Unload: Set mPopUp = Nothing
    End Sub
     
    Private Sub mSpinner_DrawFrame(ByVal po_Surface As vbRichClient5.cCairoSurface)
      Cairo.ImageList.AddSurface "mSpinner", po_Surface
      If mPopUp Is Nothing Then Exit Sub
      If mPopUp.hWnd Then mPopUp.WidgetRoot.ImageKey = "mSpinner"
    End Sub
     
    Private Sub Class_Terminate()
      StopSpinning
    End Sub
    In a Test-Project you should now have a (nearly) empty VB6-TestForm, JPBros cSpinner and the little cfSpinner-wrapper-class from above...
    In your TestForm you can now put the following code:
    Code:
    Option Explicit
    
    Private fSpinner As New cfSpinner
    
    Private Sub Form_Click() 'Start and Stop the Spinning-Popup via Form_Click
      If fSpinner.Spinner.State = spinstate_Spinning Then
         fSpinner.StopSpinning
      Else
         fSpinner.StartSpinning Me.hWnd  '<- pass the Parent-hWnd along
      End If
    End Sub
    
    Private Sub Form_Terminate() 'ensure the following in the Main-Form of your Project (the one which closes last)
      If Forms.Count = 0 Then New_c.CleanupRichClientDll
    End Sub
    The RC5-cWidgetForm (when in Popup-Mode) will not steal the Focus away from your Parent-Form.

    HTH

    Olaf

  6. #6
    PowerPoster
    Join Date
    Jun 2013
    Posts
    3,951

    Re: Spinner in VB6

    FWIW, here's another version of the cfSpinner-Class, which does not center on the current Display-Screen by default,
    but on the ParentForm instead (dynamically, even when you move or resize the ParentForm, the Spinner-Popup will remain centered on it)...

    Code:
    Option Explicit
    
    Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As Any) As Long
    
    Private WithEvents mPopUp As cWidgetForm, WithEvents mSpinner As CSpinner, mParentHwnd As Long
                           
    Private Sub Class_Initialize()
      Set mSpinner = New CSpinner
    End Sub
    
    Public Property Get Spinner() As CSpinner
      Set Spinner = mSpinner
    End Property
    
    Public Sub StartSpinning(ParentHwnd As Long)
      mParentHwnd = ParentHwnd
      mSpinner.StartSpinner
      Set mPopUp = Cairo.WidgetForms.CreateChild(ParentHwnd, True, False)
          mPopUp.WidgetRoot.ImageKeyRenderBehaviour = ImgKeyRenderLeft
      mPopUp.Show
    End Sub
    
    Public Sub StopSpinning()
      mSpinner.StopSpinner
      If Not mPopUp Is Nothing Then mPopUp.Unload: Set mPopUp = Nothing
    End Sub
     
    Private Sub mSpinner_DrawFrame(ByVal po_Surface As vbRichClient5.cCairoSurface)
      If mPopUp Is Nothing Then Exit Sub
      If mPopUp.hwnd = 0 Then Exit Sub
      Cairo.ImageList.AddSurface "Spinner", po_Surface
      Dim sz As Long: sz = mSpinner.Size
      Dim R&(0 To 3): GetWindowRect mParentHwnd, R(0)
      mPopUp.Move (R(0) + R(2) - sz) \ 2, (R(1) + R(3) - sz + 24) \ 2, sz, sz
      mPopUp.WidgetRoot.ImageKey = "Spinner"
    End Sub
     
    Private Sub Class_Terminate()
      StopSpinning
    End Sub
    HTH

    Olaf

  7. #7

    Thread Starter
    Hyperactive Member Daniel Duta's Avatar
    Join Date
    Feb 2011
    Location
    Bucharest, Romania
    Posts
    302

    Re: Spinner in VB6

    Hello Olaf, thank you for your time and support. The second version of cfSpinner-Class is almost what I expected from a spinner control. Normally, it should be running not in relation with Display-Screen (as in first example) but with a certain form. Actually I wanted to get the same behavior as the native vbHourglass. However, an weird issue occurred in the sense that the first time the spinner worked properly but when I re-run it the reference Set mPopUp does return Nothing (run-time error 91). And I have no explanation.
    Name:  Capture.JPG
Views: 57
Size:  28.2 KB
    Last edited by Daniel Duta; Jan 14th, 2019 at 02:58 AM.
    "VB code is practically pseudocode" - Tanner Helland
    "When you do things right, people won't be sure you've done anything at all" - Reed Kimble

  8. #8
    PowerPoster
    Join Date
    Jun 2013
    Posts
    3,951

    Re: Spinner in VB6

    Can only guess - but perhaps you're running an older version? (current is 5.0.0.67)
    Or there is no RC5-reference checked in?

    If that was not the reason, could you wrap the project which does not create an mPopup-instance up in a Zip and upload here?

    Olaf

  9. #9
    Frenzied Member
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    1,161

    Re: Spinner in VB6

    That's a great example of how to create an RC5 child popup window over an existing VB6 form, thanks for making that Olaf.

    Also, I can't reproduce the error Daniel has reported re: re-running the demo - I've run it many times in a row (including making live changes to the source in Break mode) without issue. I second the request for a sample project that replicates the problem.

  10. #10

    Thread Starter
    Hyperactive Member Daniel Duta's Avatar
    Join Date
    Feb 2011
    Location
    Bucharest, Romania
    Posts
    302

    Re: Spinner in VB6

    I have replaced my version 5.0.0.63 with latest from site (5.0.0.67) and now it works. Also I have kept your settings from class initialization because they seem perfect in terms of speed and appearance. Maybe you could integrate this tiny class in the main library as long as it is small and useful. I needed this feature because some users complained that do not see the vbHourGlass in some processes and consequently they are not aware when an action is over. Thank you, Olaf. Very useful class jpbro, thank you too.
    "VB code is practically pseudocode" - Tanner Helland
    "When you do things right, people won't be sure you've done anything at all" - Reed Kimble

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width