Why does $\int_a^b f(x)h'(x) \, \mathrm{d}x=0$ imply that $f$ is constant?

Seems to me like a step to prove later the Euler-Lagrange equation in the calculus of variation. Now let us assume $\int_a^b f(x)h'(x) \, \mathrm{d}x=0$ for all piecewise continuously differentiable $h(x)$ that satisfy $h(a)=h(b)=0$

We now choose a special $h$ (having the properties above) to show that $f$ must be a constant and set $$h(x)=\int_a^x f(s)-c \, \mathrm{d}s$$ Let us first show that $h(a) =0$. This is trivial. Then let us show that $h(b)=0$ : $$h(b)=\int_a^b f(s)-c \, \mathrm{d}s=\int_a^b f(s) \, \mathrm{d}s-\left . cs \right |_{s=a}^b=\int_a^bf(s)ds-(b-a)c=\\ \int_a^bf(s)ds-\int_a^bf(s)ds=0$$

Now let us show that $\int_a^b (f(x)-c)^2 dx =0$:

$$\int_a^b (f(x)-c)^2 dx =\int_a^b (f(x)-c)h'(x) dx =\\ \int_a^b f(x)h'(x) dx + \int_a^b -ch'(x) dx = \\ \int_a^b f(x)h'(x) dx -c (h(b)-h(a))$$

But we know from our assumption $\int_a^b f(x)h'(x) \, \mathrm{d}x=0$, so the first term vanishes and as $h(a)=h(b)=0$ so does the second term. This results in $$\int_a^b (f(x)-c)^2 dx =0$$

As the integral of a nonnegative function is zero then the function $(f(x)-c)^2$ must be zero a.e as well, we have $f(x)=c \qquad x\in[a,b]$