Created
December 11, 2020 23:15
-
-
Save codec-abc/daa13618f071765650081c6625b02547 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <fstream> | |
#include <windows.h> | |
#include <string> | |
#include <iomanip> | |
#include <sstream> | |
int width = 2; | |
int height = 2; | |
int32_t bitmap2x2[4] = { 0xffff0000, 0xff00ff00, 0xff0000ff, 0x00000000 }; | |
int main() | |
{ | |
if (OpenClipboard(NULL)) | |
{ | |
HDC hdc = CreateCompatibleDC(NULL); | |
HGLOBAL hmem = GlobalAlloc( | |
GHND, | |
sizeof(BITMAPV5HEADER) + width * height * 4 | |
); | |
BITMAPV5HEADER* header = (BITMAPV5HEADER*)GlobalLock(hmem); | |
header->bV5Size = sizeof(BITMAPV5HEADER); | |
header->bV5Width = width; | |
header->bV5Height = -height; | |
header->bV5Planes = 1; | |
header->bV5BitCount = 32; | |
header->bV5Compression = BI_RGB; | |
header->bV5SizeImage = 4 * width * height; | |
header->bV5AlphaMask = 0xff000000; | |
header->bV5RedMask = 0x00ff0000; | |
header->bV5GreenMask = 0x0000ff00; | |
header->bV5BlueMask = 0x000000ff; | |
header->bV5CSType = LCS_WINDOWS_COLOR_SPACE; | |
header->bV5Intent = LCS_GM_GRAPHICS; | |
header->bV5ClrUsed = 0; | |
header->bV5ClrImportant = 0; | |
header->bV5ProfileData = 0; | |
char* dst = (((char*)header) + header->bV5Size); | |
memcpy(dst, &bitmap2x2[0], 4 * sizeof(int32_t)); | |
GlobalUnlock(hmem); | |
EmptyClipboard(); | |
SetClipboardData(CF_DIBV5, hmem); | |
CloseClipboard(); | |
GlobalFree(hmem); | |
} | |
return 0; | |
} |
Author
codec-abc
commented
Dec 11, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment