|
|
Windows Clipboard 1. Open Borland C++ Builder. 2. Place a Button on the form. 3. Place an Image on the form. 4. Place a Memo box on the form. 5. Double click Button1. 6. Type the following red code in the Button1Click function: //This is what the Button1Click function should look like: //NOTE: you also need to place this include at the top of the Unit1.cpp file: #include < vcl\Clipbrd.hpp > void __fastcall TForm1::Button1Click(TObject *Sender) { TClipboard *pCB = Clipboard(); if(pCB->HasFormat(CF_BITMAP)) { Graphics::TBitmap *pBitmap = new Graphics::TBitmap(); pBitmap->LoadFromClipboardFormat(CF_BITMAP, pCB->GetAsHandle(CF_BITMAP), 0); Image1->Canvas->Draw(0, 0, pBitmap); delete pBitmap; } else if(pCB->HasFormat(CF_TEXT)) { Memo1->Lines->Text = Clipboard()->AsText; } } //--------------------------------------------------------------------------- 7. Place another button on the form. 8. Double click Button2. 9. Type the following red code in the Button2Click function: void __fastcall TForm1::Button2Click(TObject *Sender) { TClipboard *pCB = Clipboard(); Memo1->Clear(); Image1->Picture = NULL; pCB->Clear(); } 10. Run the program, press button 1. The contents of the Window Clipboard will be displayed on the image or the memo. Press button2 then button 1 again, now the clipboard is cleared. |