Generation and Nonlinear Evolution of Oblique Magnetosonic Waves: Application to Foreshock and Comets