The formulation of the question is not very clear. Here is my interpretation: If the integral $\int_\Omega fg$ vanishes whenever $g\in C_c(\Omega)$ and $\int_\Omega g=0$ then indeed the function $f$ must be constant.
We assume here that $\Omega$ is an open subset of ${\Bbb R}^n$. In the following let $\psi\in C_c({\Bbb R}^n)$ be a continuous function with compact support, say in the unit ball $B(0,1)$ in ${\Bbb R}^n$, such that $\int_{B(0,1)} \psi(x) \; d^n x=1$. It is easy to construct such a function and one may even do it so that $\psi$ is $C^\infty$. If $a\in {\Bbb R}^n$ and $\epsilon>0$ then the function $ \psi_{a,\epsilon}(x) = \frac{1}{\epsilon^n} \psi \left( \frac{x-a}{\epsilon}\right) $ will be continuous and have support in $B(a,\epsilon)$. The normalisation ensures that $\int\psi_{a,\epsilon}=1$. When $f\in C(\Omega)$ and $a\in \Omega$, then for $\epsilon>0$ small enough, $B(a,\epsilon)\subset \Omega$ and as $f$ is continuous at $a$ we see that $ f(a) = \lim_{\epsilon\rightarrow 0} \int f(x) \psi_{a,\epsilon}(x) \; d^n x.$
Now, let $a,b\in \Omega$ and consider the function $g_\epsilon= \psi_{a,\epsilon}-\psi_{b,\epsilon}$. For $\epsilon>0$ small enough we have $\int_\Omega g_\epsilon = 0$, so by the hypothesis on $f$ we deduce:
$ 0 = \lim_{\epsilon\rightarrow 0}\int_\Omega f \cdot g_\epsilon = \lim_{\epsilon\rightarrow 0} \int_\Omega f(x) (\psi_{a,\epsilon}(x)-\psi_{b,\epsilon}(x))\; d^n x = f(a)-f(b)$ So as $f(a)=f(b)$ for any two points $a,b\in \Omega$ we conclude that $f$ is constant.
A similar though more technical argument works if $f$ is only assumed locally integrable rather than continuous, with the conclusion that a.e. $f$ is constant.