What's the correct way. Should I zero-pad a signal before or after applying a windowing function?
If done correctly, the order should not matter. You apply windowing to remove the jumps at the end of the signal segment by fading the values there to zero. Zero-padding then continues with zeros. Irregardless if padded or not, the windowing should only be applied to the original signal segment.
The wrong way would be to zero-padding and then apply windowing to the new longer signal over its full length, i.e., without regard to the position of the jumps. This would not remove the jumps and thus keep the background in the spectrum non-related to the frequency content of the signal but the segmentation method.
I would window and then zero-pad.
The purpose of the window is to smooth out the boundary transitions. When you zero-pad you are introducing a very abrubt transition at the zero-pad point which, if you want the window to be effective, is where the smoothed out transition should happen.
You must window your data, before zero-padding. The point of the windowing process is to smooth out the end-points of your data prior to taking the FFT, so that we reduce spectral leakage.
If you zero-pad and then window, you are making the implicit statement that all the zeros you added are part of your data, which is incorrect.