'====================================================================
' Button grid demo, modal dialog as main.
'====================================================================
' Minesweeper is next

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

'% review

uses dialogs


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

  sys id, event
  static int state[100]

  select case uMsg
            
    case WM_COMMAND
      id=loword(wParam)
      event=hiword(wParam)

      if id=IDCANCEL then EndDialog( hDlg, null)
         
      if event = BN_CLICKED then      
        if state[id+100] then
          SetDlgItemText( hDlg, id, "" )
          state[id+100] = 0
        else
          SetDlgItemText( hDlg, id, "X" )
          state[id+100] = 1
        end if
      end if
        
    case WM_CLOSE
      EndDialog( hDlg, null )
    
  end select

  return 0
end function

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

short id, r, c

Dialog( 0, 0, 122, 130, "Button Grid Demo",
             WS_OVERLAPPED or WS_SYSMENU or DS_CENTER )

id = 100
for c = 10 to 100 step 10
  for r = 10 to 100 step 10
    if id > 100 then
      PushButton( "", id, r, c, 9, 9)
    else
      DefPushButton( "", id, r, c, 9, 9)
    end if
    id += 1
  next
next

CreateModalDialog( 0, @DialogProc, 0 )

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