The hanning window is applied to the time-domain data first, and then the data is passed to fft(). Because the sample you are using may have discontinuities (large assumed jumps) at the beginning and end of the sample, this puts unwanted harmonics into your fft - the hanning et al. windows reduce the size of the discontinuity.
So, your first example, but applying the hanning window:
Code:
t=(0:99)/100;
S=sin(2*pi*25*t);
Y=fft(S .* hanning(length(S))');
plot(abs(Y))