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

$ filename "Statusbar.exe"
'uses rtl32
'uses rtl64

'% review

uses dialogs


function DialogProc( sys hDlg, uint uMsg, sys wParam, lParam) as sys callback
indexbase 0

  static sys hWndSB
  static RECT rcDlg, rcSB

      hWndSB = GetDlgItem( hDlg, 100 )
      
  select case uMsg

    case WM_INITDIALOG

      int widths[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, @widths )

      return true

    case WM_SIZE

      int sbHeight
      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, status)
      SendMessage( hWndSB,SB_SETTEXT,1," part 1")
      SendMessage( hWndSB,SB_SETTEXT,2," part 2")
      SendMessage( hWndSB,SB_SETTEXT,3," part 3 ")

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

    case WM_CLOSE

      EndDialog( hDlg, null )

  end select

  return 0
end function

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

init_common_controls()

Dialog( 0, 0, 120, 90, "Status Bar Demo",
        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, STATUSCLASSNAME, 0, 0, 0, 0, 0 )

CreateModalDialog( null, @DialogProc, 0 )

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