void CopyBitmap(HWND hwnd, HBITMAP* Dbmp, const HBITMAP* Sbmp)
{
char* bits = nullptr;
static BITMAP bm;
TCHAR Error[MAX_PATH];
GetObject(*Sbmp, sizeof(BITMAP), &bm);
unsigned bitsize = bm.bmWidthBytes * bm.bmHeight * bm.bmPlanes;
try
{
bits = new char[bitsize];
}
catch (const std::exception& e)
{
auto len = MultiByteToWideChar(CP_ACP, 0, e.what(), -1, Error, MAX_PATH);
Error[len] = '\0';
MessageBox(hwnd, Error, NULL, MB_OK);
return;
}
GetBitmapBits(*Sbmp, bitsize, bits);
*Dbmp = CreateBitmapIndirect(&bm);
SetBitmapBits(*Dbmp, bitsize, bits);
delete[]bits;
}