how could window function really suppress those frequencies that we don't want?
You are right that the effect of windowing is the same for the design of FIR filters and for spectral analysis. You will always have a compromise between main lobe width and relative side lobe level (relative to the main lobe). The main lobe width determines the frequency resolution, and the relative side lobe level determines the amount of spectral leakage. A rectangular window has a narrow main lobe (desirable), and relatively large side lobes (undesirable). Other windows achieve different compromises between those two parameters. In FIR filter design, the equivalents to frequency resolution (main lobe width) and leakage (side lobe level) are transition band width and stop band rejection.

You should read the classic paper by Fred Harris: On the Use of Windows for Harmonic Analysis with the Discrete Fourier Transform.