Wavenumber locking and pattern formation in spatially forced systems