Hakim al-Umma Shaykh Ashraf Ali Thanawi (may Allah have mercy on him) said,
Nothing happens without determination.
The real treatment to prevent lustful glances is to think at that moment:
“Allah SWT is watching me now and on the Day of Judgment I will be questioned regarding this. And if Allah SWT condemns me for punishment what will happen of me?”
By recalling this repeatedly again and again one will attain success.
Therefore, make strong determination.
This is the only treatment.
Initially for few days there will be some hardship indeed, but eventually, inshaAllah, it will become a habit. And then the gratification and peace you find in it can only be imagined of.
(Basair-e-Hakeemul-e-Ummat, page 369)