An approach to photonic generation of a windowed binary phase-coded microwave waveform with suppressed spectrum sidelobes is proposed and demonstrated. An optical double sideband plus carrier signal with the carrier and the two sidebands being orthogonally polarized is generated by a dual-polarization quadrature phase shift keying (DP-QPSK) modulator, with the generated signal sent to a phase modulator (PM) where phase coding is performed. The PM can support phase modulation in two orthogonal polarization directions. The phase-modulated signals are projected to one polarization direction and detected at a photodetector (PD). Switching the polarity of the coding signal, a phase shift is introduced. Since the amplitude of the generated signal is dependent on the amplitude of the input coding signal, a windowing function is applied to the generated waveform by using a windowed input phase coding signal, to suppress the sidelobes in the spectrum of the generated microwave waveform. The key features of the proposed waveform generator include all-optical generation without the need of electronic components and optical filters, thus ensuring a wide operating frequency range. The proposed phase-coded microwave waveform generator has also the ability to switch between the fundamental and harmonic carrier frequency by controlling the modulator bias voltages. Experimental results show that, using a windowed 64-bit Gaussian pseudo-random binary sequence coding signal, a phase-coded microwave waveform is generated with the sidelobes of the spectrum largely suppressed by 20 dB and a pulse compression ratio as large as 133. Generation of binary phase-coded microwave waveforms at the 2nd harmonic carrier frequencies is also demonstrated experimentally.