How do you plan to use the query from x++ code when you have a query based report and you are reluctant to write a controller?
Making query invisible to user is already explained, create a controller and override the showQueryValues method in the initial reply, please browse the initial replies.
For other queries please use a different thread