'====================================================================
' Control grouping demo, modal dialog as main.
'====================================================================

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

'% review

uses dialogs

==============================================
'MAIN CODE
=============================================
 
function DialogProc( sys hDlg, uint uMsg, sys wParam, lParam ) as int callback

  select case uMsg
  
    case WM_INITDIALOG
      return true

    case WM_COMMAND
      int ctrl, res
      string state
    
      if hiword(wParam) = BN_CLICKED then
        if loword(wParam) = 105 then
          state = ""
          for ctrl = 101 to 104
            res = IsDlgButtonChecked( hDlg, ctrl )
            if res = BST_CHECKED then
              state = state & "1"
            else
              state = state & "0"
            end if
          next
          MessageBox( hDlg, state, "State", 0 )
        end if
      end if    
    
      select case loword(wParam)
        case IDCANCEL
           EndDialog( hDlg, null )
      end select
      
    case WM_CLOSE
      EndDialog( hDlg, null )
                
  end select

  return 0
end function

sub winmain()

  Dialog( 0, 0, 150, 100, "Group Demo",
        WS_OVERLAPPED or WS_SYSMENU or DS_CENTER )

  GroupBox( "GroupBox1", 100, 10, 5, 80, 35 )

  RadioButton( "AutoRadioButton&1", 101, 15, 15, 70, 10,
                   WS_TABSTOP or WS_GROUP )

  RadioButton( "AutoRadioButton&2", 102, 15, 25, 70, 10 )

  GroupBox( "GroupBox2", 110, 10, 45, 80, 35 )

  AutoRadioButton( "AutoRadioButton&3", 103, 15, 55, 70, 10,
                   WS_TABSTOP or WS_GROUP )

  AutoRadioButton( "AutoRadioButton&4", 104, 15, 65, 70, 10 )

  DefPushButton( "&Get State", 105, 100, 10, 38, 12,
                 WS_TABSTOP or WS_GROUP )

  PushButton( "Cancel", IDCANCEL, 100, 28, 38, 12,  WS_TABSTOP )

  CreateModalDialog( null, @DialogProc, 0 )

end sub

winmain()

