Results 1 to 4 of 4

Thread: ProgressBar into a StatusBar control on an MDI form

  1. #1
    Guest

    Unhappy

    I'm looking for some help on how to embed a progressbar into a statusbar control on an MDI form. I've attempted using some of the API examples but the move method doesn't seem to be working properly. The ProgressBar appears right below my button bar instead of showing up within the StatusBar pannel.

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Lightbulb

    Sure. You can use this procedure I wrote a while back:
    Code:
    Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
    End Type
    Private Const WM_USER As Long = &H400
    Private Const SB_GETRECT As Long = (WM_USER + 10)
    
    Public Sub ShowProgressInStatus(pProgress As ProgressBar, pStatus As StatusBar, pPanelIndex As Integer)
        Dim tRC As RECT
    
        pProgress.Appearance = ccFlat
        'Get the size of the given panel
        SendMessage StatusBar1.hwnd, SB_GETRECT, pPanelIndex - 1, tRC
        'Convert to Twips
        With tRC
            .Top = (.Top * Screen.TwipsPerPixelY) + 20
            .Left = (.Left * Screen.TwipsPerPixelX) + 20
            .Bottom = (.Bottom * Screen.TwipsPerPixelY) - .Top
            .Right = (.Right * Screen.TwipsPerPixelX) - .Left - 20
        End With
        'Reparent the ProgressBar to the statusbar
        With ProgressBar1
            SetParent .hwnd, StatusBar1.hwnd
            .Move tRC.Left, tRC.Top, tRC.Right, tRC.Bottom
            .Visible = True
            .Value = 0
        End With
    Then you can call it like this:

    ShowProgressInStatus Progress1, Status1, 1

    This will put ProgressBar into the first panel of the StatusBar.

  3. #3
    Guest

    Question


    I'm looking for some help on how to embed a progressbar into a statusbar control on an MDI form. I've attempted using some of the API examples but the move method doesn't seem to be working properly. The ProgressBar appears right below my button bar instead of showing up within the StatusBar pannel.

    I'm afraid this isn't working for me... I've cut and pasted the code and modified where you had statusbar1 and panelbar1 to use the pStatus and pPanel parameters however I'm still having the same problems. Just as an FYI I'm running on NT, so I'm not sure if there is a difference in regrads to the API calls. Lastly, I created a cmdButton and have that increment to 1000 in order to test the progress bar. When I click on the button the ENTIRE status bar looks as if it's being painted over but you can't see any tick marks. Lastly, you can see a rectangular frame above the statusbar...

    Any ideas????

  4. #4
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Lightbulb

    It is working just fine. In order for you to see the Progress, you will have to change it's value. Here is an example. Drop a Timer control on the form and use this code:
    Code:
    Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
    End Type
    Private Const WM_USER As Long = &H400
    Private Const SB_GETRECT As Long = (WM_USER + 10)
    
    Public Sub ShowProgressInStatus(pProgress As ProgressBar, pStatus As StatusBar, pPanelIndex As Integer)
        Dim tRC As RECT
    
        pProgress.Appearance = ccFlat
        'Get the size of the given panel
        SendMessage StatusBar1.hwnd, SB_GETRECT, pPanelIndex - 1, tRC
        'Convert to Twips
        With tRC
            .Top = (.Top * Screen.TwipsPerPixelY) + 20
            .Left = (.Left * Screen.TwipsPerPixelX) + 20
            .Bottom = (.Bottom * Screen.TwipsPerPixelY) - .Top
            .Right = (.Right * Screen.TwipsPerPixelX) - .Left - 20
        End With
        'Reparent the ProgressBar to the statusbar
        With ProgressBar1
            SetParent .hwnd, StatusBar1.hwnd
            .Move tRC.Left, tRC.Top, tRC.Right, tRC.Bottom
            .Visible = True
            .Value = 0
        End With
    End Sub
    
    Private Sub Form_Load()
        Timer1.Interval = 100
        ShowProgressInStatus ProgressBar1, StatusBar1, 1
    End Sub
    
    Private Sub Timer1_Timer()
        With ProgressBar1
            If .Value = .Max Then
                .Value = .Min
            Else
                .Value = .Value + 1
            End If
        End With
    End Sub

Posting Permissions

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



Click Here to Expand Forum to Full Width