Re: copy bitmap to windows clipboard
hi jana,
your problem is not that your clipboard functions are not working, the
loading of the bitmap fails - you would have recognized that if you
implemented a proper error handling.
by replacing the LoadBitmap() [i'm not using this function unless i
load a "standard" bitmap from the resource] with a call of the function
LoadImage(). see the code as follows:
HBITMAP hBmp = (HBITMAP)::LoadImage(NULL, "C:\\test.bmp",
IMAGE_BITMAP, 0,0, LR_LOADFROMFILE);
if (hBmp == NULL)
{
// bitmap konnte nicht geladen werden
return;
}
if (!::OpenClipboard(NULL))
{
// clipboard konnte nicht ge=F6ffnet werden
::DestroyObject(hBmp);
return;
}
if (!::EmptyClipboard())
{
// EmptyClipboard() fehlgeschlagen
::CloseClipboard();
::DestroyObject(hBmp);
return;
}
if (::SetClipboardData(CF_BITMAP, hBmp) == NULL)
{
// SetClipboardData() fehlgeschlagen
::CloseClipboard();
::DestroyObject(hBmp);
return;
}
::CloseClipboard();
never expect to go anything smooth, always expect the functions to fail
on whatever reason (so you may get a robust application without it to
crash every now and than) - e.g. the Clipboard may just be locked from
another process so you can't access it currently.
have a nice day,
Martin