Hamiltonian approach to the dynamical Casimir effect