To stop the behavior
This reminds me of the Miss Manners answer to when you catch guests looking in your bathroom medicine cabinet: "May I help you find something?" This puts the face on things that they are in legitimate need of something and you, of course, will play the consummate host/hostess by catering to their every (legitimate) need.
But the clearly-communicated subtext is "what the heck are you doing in my private things"? This is received loud and clear, but you're providing a face-saving social fiction to act out, allowing them to say "um, yeah, I need some headache medicine" if they really feel embarrassed, or they can just lamely say "no thanks, I'm okay" while still feeling less accused or attacked, because the question they're answering so lamely is a red herring for the real issue. (And, in the case of bathroom cabinets, you never know, perhaps your guest is in real need but was embarrassed to ask.)
Similarly, if someone is looking at your screen more than casually or coincidentally, you could take a similar tack by saying "Is something wrong with my email?" or "May I help you find something on my computer?", being sure to have a neutral and helpful/curious attitude and tone rather than a sarcastic or snide one.
Again, the key here is to put a facade of legitimacy on their actions, while still accomplishing the confrontation you desire, leaving them an out to say, "Oh no, that's okay, I don't need anything" or "no, there's nothing wrong" and desist from their actions.
To prevent someone from actually seeing what's on your screen
If you have something up that you truly don't want seen, trying to hide it in reaction to someone's unexpected arrival or inspection (once they're actually present and looking at you) will almost certainly prompt him/her to look harder and try to assess what's wrong with the content—why you don't want it seen.
In that case, and when the above technique is too risky (because it actually calls attention to what they're looking at), just turn toward them and give them your full attention physically, even standing up in order to (seemingly) have a fully-engaged conversation, without locking your screen. This is just about your only hope for preventing someone from reading what's on your screen when it has something you'd rather keep private and you don't want to direct attention to the fact that you'd prefer they don't look right now. I have used this technique successfully myself, but you have to be absolutely cool or you'll give it away.
As a last-ditch resort for something you truly cannot tolerate someone seeing, you could lock your screen if you provide a suitable pretext for doing so. Note that you must not seem to directly answer why you locked your screen, since you're acting as if your screen locking was not in response to the person's arrival—a key component in pulling this off successfully. The person must make the connection, "oh, that's why he locked the screen", or better yet, he should not even notice the action because it doesn't seem unusual in context.
For example, you could stand up and say, you know, I'm sorry to be rude, but can I talk to you in 5 minutes? I really have to make a pit stop", then head into the bathroom. Obviously, as you stood up, you locked the screen quickly (Windows: Win + L; Mac: move cursor to hotspot corner or Ctrl + Command + Q).