many trojan horses allow hackers access to the infected computers.. and yes many variants allow the person to view the webcam as well as the built in microphone. Some worms can do similiar things before they replicate, and some are just flat out destructive like the stuxnet worm. That one appears to be designed to specifically take down infrastructural systems like power plants (look at Iran's Nuclear Plant that is currently under attack) as well as many infections in India and a couple here in the good old USA.
Hacking into cams has been a part of a few TV shows, and is a very real thing. As long as the camera is connected to an energy source they can activate it.
It is a scary thought, but they have to get into your computer first, so the safest thing is to stay on secured networks.
If you are on an unsecured network you can keep a separate camera unplugged, or a built in camera covered some paper or dark tape, it shouldn't be an issue.
You can go into your computer's files and disable your built in web cam and microphone so the system can't even detect them, but there is a chance that a hacker might be able to enable them.
I know several colleges and high schools that have student use laptops have their built in cams disabled.