Code:
 dialog new_table {
  title "New Project"
  size -1 -1 124 94
  option pixels
  button "OK", 1, 15 15 75 25, ok
  button "Cancel", 2, 15 45 75 25, cancel
}
menu * {
  New Table : dialog $iif(!$dialog(new_table),-md,-ev) new_table new_table
}
on *:dialog:new_table:close:*:{
  echo 4 -a $iif($did,$did,NULL)
}
 

If you click the OK button, then the script echoes 1
If you click the Cancel button, then the script echoes 2
If you click the X, then the script echoes 2

If you remove the line with the Cancel button in it, then run the script and click the X, you'll see NULL

I hope this is sufficient explanation for your requirements.