
'====================================================================
'' Status bar demo, modal dialog as main.
'====================================================================

#include "dialogs.bas"

'====================================================================

Function DialogProc( Byval hDlg As  HWND, _
                     Byval uMsg As UINT, _
                     Byval wParam As WPARAM, _
                     Byval lParam As LPARAM ) As Integer

  Static As HWND hWndSB
  Static As RECT rcDlg, rcSB

  Select Case uMsg

    Case WM_INITDIALOG

      Dim As Integer widths(0 To 3)

      hWndSB = GetDlgItem( hDlg, 100 )

      GetClientRect( hDlg, @rcDlg )
      widths(0) = rcDlg.right \ 4
      widths(1) = rcDlg.right * 2 \ 4
      widths(2) = rcDlg.right * 3 \ 4
      widths(3) = -1              '' part extends to window border

      SendMessage( hWndSB, SB_SETPARTS, 4, cast(LPARAM,@widths(0)) )

      Return true

    Case WM_SIZE

      Dim As Integer sbHeight
      Dim As String status

      GetClientRect( hDlg, @rcDlg )
      GetWindowRect( hWndSB, @rcSB )
      sbHeight = rcSB.bottom - rcSB.top + 1

      MoveWindow( hWndSB, 0, rcDlg.bottom - sbHeight , _
                  loword(lParam), rcDlg.bottom - sbHeight, false )

      '' For a simple status bar with just one part,
      '' the text can be set with WM_SETTEXT.
      ''
      status = " " & Str(rcDlg.right) & "x" & Str(rcDlg.bottom)
      SendMessage( hWndSB,SB_SETTEXT,0,cast(LPARAM,Strptr(status)) )
      SendMessage( hWndSB,SB_SETTEXT,1,cast(LPARAM,@" part 1") )
      SendMessage( hWndSB,SB_SETTEXT,2,cast(LPARAM,@" part 2") )
      SendMessage( hWndSB,SB_SETTEXT,3,cast(LPARAM,@" part 3 ") )

      rcDlg.bottom -= sbHeight
      InvalidateRect( hDlg, @rcDlg, true )

    Case WM_CLOSE

      EndDialog( hDlg, null )

  End Select

  Return 0

End Function

'====================================================================

Dim As LPDLGTEMPLATE lpdt

InitializeCommonControls

Dialog( 1, 0, 0, 120, 90, "Status Bar Demo", lpdt, _
        WS_OVERLAPPEDWINDOW Or DS_CENTER )

'' Instead of trying to anticipate the position and/or size of
'' the controls, just use zeros and set the correct values in
'' the WM_SIZE handler.
''
Control( 100, 0, 0, 0, 0, "", 0, STATUSCLASSNAME )

CreateModalDialog( 0, @DialogProc, 0, lpdt )

'====================================================================
 