// Program to load clipboard CF_DIB data to desktop // Example: C:\MinGW\Progs>g++ ClipbrdReadDIB.cpp -lgdi32 -o crdib.exe // Ref: https://stackoverflow.com/questions/30552255/how-to-read-a-bitmap-from-the-windows-clipboard // Ref: http://www.cplusplus.com/reference/fstream/ofstream/open/ #include #include #include typedef struct { std::uint32_t biSize; std::int32_t biWidth; std::int32_t biHeight; std::uint16_t biPlanes; std::uint16_t biBitCount; std::uint32_t biCompression; std::uint32_t biSizeImage; std::int32_t biXPelsPerMeter; std::int32_t biYPelsPerMeter; std::uint32_t biClrUsed; std::uint32_t biClrImportant; } DIB; typedef struct { std::uint16_t type; std::uint32_t bfSize; std::uint32_t reserved; std::uint32_t offset; } HEADER; typedef struct { HEADER header; DIB dib; } BMP; int wmain(int argc, char* argv[]) { std::cout<<"Format Bitmap: "<(dib); BMP bmp = {0}; bmp.header.type = 0x4D42; bmp.header.offset = 54; bmp.header.bfSize = info->biSizeImage + bmp.header.offset; bmp.dib = *info; std::cout<<"Type: "<(&bmp.header.type), sizeof(bmp.header.type)); ofs.write (reinterpret_cast(&bmp.header.bfSize), sizeof(bmp.header.bfSize)); ofs.write (reinterpret_cast(&bmp.header.reserved), sizeof(bmp.header.reserved)); ofs.write (reinterpret_cast(&bmp.header.offset), sizeof(bmp.header.offset)); ofs.write (reinterpret_cast(&bmp.dib.biSize), sizeof(bmp.dib.biSize)); ofs.write (reinterpret_cast(&bmp.dib.biWidth), sizeof(bmp.dib.biWidth)); ofs.write (reinterpret_cast(&bmp.dib.biHeight), sizeof(bmp.dib.biHeight)); ofs.write (reinterpret_cast(&bmp.dib.biPlanes), sizeof(bmp.dib.biPlanes)); ofs.write (reinterpret_cast(&bmp.dib.biBitCount), sizeof(bmp.dib.biBitCount)); ofs.write (reinterpret_cast(&bmp.dib.biCompression), sizeof(bmp.dib.biCompression)); ofs.write (reinterpret_cast(&bmp.dib.biSizeImage), sizeof(bmp.dib.biSizeImage)); ofs.write (reinterpret_cast(&bmp.dib.biXPelsPerMeter), sizeof(bmp.dib.biXPelsPerMeter)); ofs.write (reinterpret_cast(&bmp.dib.biYPelsPerMeter), sizeof(bmp.dib.biYPelsPerMeter)); ofs.write (reinterpret_cast(&bmp.dib.biClrUsed), sizeof(bmp.dib.biClrUsed)); ofs.write (reinterpret_cast(&bmp.dib.biClrImportant), sizeof(bmp.dib.biClrImportant)); ofs.write (reinterpret_cast(info + 1), bmp.dib.biSizeImage); ofs.close(); GlobalUnlock(dib); } else std::cout<<"hClipboard was NOT able to be GlobalLocked.\n"; } CloseClipboard(); } else std::cout<<"We were NOT able to open the Clipboard.\n"; } return 0; }