PDA

View Full Version : Copy BMP to and from Clipboard!



Intrigued
11-03-2005, 06:22 PM
Well, for someone(s) with expertise in C++ here is how code from:

http://www.codeproject.com/clipboard/clipboard_faq.asp?df=100&forumid=137&exp=0&select=342806

CODE:


Reading and writing a bitmap

Reading and writing a bitmap is only marginally trickier. The basic idea remains the same. Here is an example of saving a bitmap to the clipboard.

if ( OpenClipboard() )
{
EmptyClipboard();
//create some data
CBitmap * junk = new CBitmap();
CClientDC cdc(this);
CDC dc;
dc.CreateCompatibleDC(&cdc);
CRect client(0,0,200,200);
junk->CreateCompatibleBitmap(&cdc,client.Width(),client.Height());
dc.SelectObject(junk);

//call draw routine here that makes GDI calls
DrawImage(&dc,CString("Bitmap"));

//put the data on the clipboard
SetClipboardData(CF_BITMAP,junk->m_hObject);
CloseClipboard();

//copy has been made on clipboard so we can delete
delete junk;
}

As with the other examples, here is an example of getting a bitmap from the clipboard. In this simple example we will just Blt it to the cleint DC.

if ( OpenClipboard() )
{

//Get the clipboard data
HBITMAP handle = (HBITMAP)GetClipboardData(CF_BITMAP);
CBitmap * bm = CBitmap::FromHandle(handle);

CClientDC cdc(this);
CDC dc;
dc.CreateCompatibleDC(&cdc);
dc.SelectObject(bm);
cdc.BitBlt(0,0,200,200,&dc,0,0,SRCCOPY);

CloseClipboard();

}

Corey
11-03-2005, 06:38 PM
Neato! :D