You will find the code in this artile:
Win32: Capture an image
http://www.experts-exchange.com/Programming/System/Windows__Programming/A_1739-Win32-Capture-an-image.html
Funtcion Capture makes an image and saves it in a file.
Standard BMP-file has a a file header (BITMAPFILEHEADER) in the beginning, then BITMAPINFOHEADER and the bit-array. Last two parts is the dib-section, actually.
There is a short and clear article in MSDN:
Storing an Image
http://msdn.microsoft.com/en-us/library/dd145119(v=VS.85).aspx