| 
              #include <stdio.h>#include <Windows.h>
 
 LPBYTE AllocateBits(int nWidth, int nHeight, int nBitcCount, int *pSize)
 {
 *pSize = ((nWidth * nBitcCount + 31) / 32) * 4 * nHeight;
 if (*pSize < 0)
 *pSize = -*pSize;
 return (LPBYTE)malloc(*pSize);
 }
 
 int main(void)
 {
 BITMAPINFOHEADER bmh;
 HBITMAP hbmp;
 HDC hdc;
 int size;
 LPBYTE pBits;
 
 ZeroMemory(&bmh, sizeof(bmh));
 bmh.biSize = sizeof(bmh);
 bmh.biBitCount = 24;
 bmh.biPlanes = 1;
 bmh.biWidth = 200;
 bmh.biHeight = 100;
 
 pBits = AllocateBits(bmh.biWidth, bmh.biHeight, bmh.biBitCount, &size);
 memset(pBits, 0x99, size);
 
 hdc = GetDC(NULL);
 hbmp = CreateDIBitmap(hdc, &bmh, CBM_INIT, pBits, (BITMAPINFO *)&bmh, DIB_RGB_COLORS);
 ReleaseDC(NULL, hdc);
 
 OpenClipboard(NULL);
 EmptyClipboard();
 SetClipboardData(CF_BITMAP, hbmp);
 CloseClipboard();
 
 free(pBits);
 return 0;
 }
 |