You can simply make this a rule at your place of work. At my job, we are all supposed to lock the computers before going to lunch or going to a meeting. Our IT guy kindly reminds us to always lock the computer if he happens to see this is an issue.
A fun way you can make sure everyone is doing this is just to visit computers that are left alone and unlocked. Poke around on the person's computer and open up their browser. You can see what they've been up to that day. When they return to their desk, let them know you wouldn't have done that if they'd just simply locked their computer. Sure, they might get angry, but hey, it's the company's property and if the computer user wanted people not nosing around on the computer, they should lock it next time.