Most modern operating systems will do this for you.
On Win32, the PrintScreen key will capture the whole screen to the clipboard, and alt-PrintScreen (or is it Shift?) will capture just the current window.
Most modern Linux systems have window managers that do something similar - GNOME automatically saves them as PNGs, as well.
It mostly extendes the Windows' printscreen functionality so that with ctrl-alt-printscreen you can actually drag and "slice" portion of screen for capture. It places this into the clipboard same way as normal printscreen does. Now the problem usually is, how to save this clipboard into something usable (other than bmp files). My program solves this by sitting in the notification area as an icon and providing menu to save clipboard image into jpg, gif or png image.