'====================================================================
' Status bar demo, modal dialog as main.
'====================================================================

'% review

uses dialogs
'namespace


% DS_CENTER=0x0800
% SB_SETTEXT=0x401
% SB_SETPARTS=0x404

! GetDlgItem lib "user32.dll" (sys hDlg, int nIDDlgItem) as sys

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

'====================================================================

sys lpdt : dyn::init(lpdt)

init_common_controls()

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, STATUSCLASSNAME, 0, 0, 0, 0, 0 )

CreateModalDialog( null, @DialogProc, 0, lpdt )

'====================================================================