Seventh chapter-Clipboard and Dynamic Data Exchange (i) (3)

Source: Internet
Author: User

7.1.3.3 paste

Pastes the image from the Clipboard to first detect the data format on the Clipboard. If the format is Cf_bitmap, the Assign method of the target bitmap is invoked to paste the image.

The list of procedures is as follows.

Procedure Tform1.pastebuttonclick (Sender:tobject);

Var

Bitmap:tbitmap;

Begin

If Clipboard.hasformat (Cf_bitmap) Then

Begin

Bitmap: = tbitmap.create;

Try

Bitmap.assign (Clipboard);

Image.Canvas.Draw (0, 0, Bitmap);

Finally

Bitmap.free;

End

End

End

Try...finally is a resource protection block, the 12th chapter.

7.1.4 to establish its own clipboard watcher

In this section, we'll build our own Clipboard Watcher to save the bitmap that was intercepted in the Clipboard.

Windows allows the user to create their own clipboard watcher and adds the program to a clipboard watcher chain. In a chain, a pre-position program is obligated to pass messages about the Clipboard to the watcher immediately following it. The program at the top of the chain sends the Clipboard message directly from the Windows message loop mechanism.

Create a clipboard watcher, which must first be able to respond to the appropriate Windows messages. For readers who are familiar with Microsoft Visual Basic, this is where they get a headache. But Delphi has a good performance in this regard: by using the keyword message, a user can define a procedure to respond to a specific Windows message. Such as:

Procedure Wmdrawclipboard (var msg:twmdrawclipboard);

Message Wm_drawclipboard;

Can respond to wm_drawclipboard messages. Class Twmdrawclipboard is a subclass of message class messages. Delphi has redefined all the messages so that users can use them directly to refer to their easily memorized data members without having to decompose the message themselves. Although this does not count as a major improvement, but it embodies the Delphi everywhere for the convenience of the user's characteristics.

The purpose of the program we are going to build is to save the bitmap that was intercepted on the Clipboard. In the writing process of this book, this work is a lot of existence. Although using Windows tools paintbrush (brushes), you can do this by pasting, saving, and so on, there are some problems:

1. The process of frequent switching effect efficiency, when there are a large number of bitmaps exist more so;

2. Brushes have a nasty flaw: bitmaps outside the client area are truncated when the bitmap on the Clipboard is larger than the client area of the brush interface. It is often necessary to adjust the size of the brush client area according to the size of the captured bitmap and to paste again. And if you start to adjust the Brush client area to large enough, it will overwrite some useful information on the screen.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.