You don't have to select and force the player to press cancel, you can just issue the building the cancel order.
I would also like to note that the player won't get back 100% of the resources unless you set the gameplay constants so.
There's actually a third way, I think I would go with: Aura.
Give all buildings an aura with 200 range, make this aura affect units as well, so players would have a visible indicator where can they build (the aura buff / model on the builder).