Contents
Clipboard  Sample Help

Sample Description: Clipboard

Points of Interest

Accessing the Clipboard from Envelop

Transferring Text

Transferring Pictures

Drag and Drop Bitmap Files

Testing the Application

Control

XferData

For Help on Help, Press F1


Clipboard

The purpose of this sample is to give you an overview of the Clipboard and how you can use it with the Envelop application.

The clipboard is provided with the Windows environment as a temporary holding place for text and graphics. It is available whenever Windows is run and is accessible throughout the Windows environment.

The clipboard can be used to transfer data from one application to another, or to a new location within the same application.For example, using Windows Notepad, you can create and select some text information, then copy it to the Clipboard using the Edit/Copy menu command. Next, you can use Envelop's shortcut key CTRL-V to paste this text into a valid spot in Envelop, such as a TextBox.

Each time you copy to the clipboard its existing contents are erased. For example, you cannot add text to the end of a paragraph that already exists in the clipboard. The existing paragraph would be deleted and the new text would be put in the clipboard in its place.

The Clipboard is an independent accessory that has specialized data-conversion features for manipulating different data formats.

To access the Clipboard program directly, go to the Window's Main Program group and launch the "Clipboard Viewer" application. By doing this you can view the contents of the clipboard as well as store it to disk. You can also get data from a file that was saved earlier.


Accessing the Clipboard from Envelop

Envelop can access the Windows Clipboard through program code using Envelop's XferData object. Below is a list of methods used to interchange data with the Clipboard.

Method	To do this

Copy	Copy an XferData's selected formats to a new XferData

GetData	Get an XferData object containing the data formats of an object

GetPicture	Get an XferData object containing pictorial formats

SetData	Set an object's data formats from an XferData object

SetPicture	Set the pictorial formats

On a very basic level, XferData handles information placed on the Windows clipboard, including both standard and user defined clipboard formats.

XferData describes the data transfer for metafiles, Dibs, and Bitmaps (with Palette). It can search for specific formats, and combinations of format, media, and aspect. It can also get the number of formats offered and accepted by a metafile, Dib, or Bitmap.

With XferData you can access the clipboard to examine the clipboard contents or simply cut or paste. When DragMode property is set to 0 (the default) then XferData accesses clipboard.


Transferring Text

Viewing text from the Clipboard is handled in this sample by clicking the "View Text in Clipboard" button. The following Click method is executed when this button is clicked:

Sub cmdViewText_Click()

  Dim xf as New XferData

  txtViewText.Text = xf.Text

End Sub

This method creates a new XferData object and sets the contents of the txtViewText TextBox on the sample form. The Text property of the XferData object will contain the current text information on the Clipboard.

To copy text to the Windows Clipboard, start by entering some text in the txtViewText box on the sample form. This is the box shown at the top of the form. Then Click the "Copy Text to Clipboard" button. The following Click method is executed when this button is clicked:

Sub cmdCopyText_Click()

  Dim xf as New XferData

  xf.Text = txtViewText.Text

End Sub

This method creates a new XferData object and sets the Text property of this object to be the contents of our txtViewText box. When the Text property of an XferData object is set to some text string, the result is automatically copied to the Windows Clipboard.


Transferring Pictures

Viewing pictures from the Clipboard is handled in this sample by clicking the "View Image in Clipboard" button. The following Click method is executed when this button is clicked:

Sub cmdViewPicture_Click()

  Clip = XferData.Copy

  BitmapSource.SetPicture Clip.GetPicture

  RefreshBitmap

End Sub

Sub RefreshBitmap

  With imgViewPicture

    .ScaleX = 1

    .ScaleY = 1

    .CropXOffset = 0

    .CropYOffset = 0

    .Refresh

  End With

End Sub

This method creates a new XferData object called "Clip" by executing the XferData object's Copy method. In the sample, the Image control at the bottom of the form references a Bitmap object named BitmapSource. The GetPicture method of the Clip XferData object is used to get the image information as an object and pass it to the SetPicture method of the Bitmap object.

Once the transfer has taken place, a Sub named RefreshBitmap is called. This routine basically sets the scale factors of the picture from the Clipboard and refreshes the control.

To copy a picture to the Windows Clipboard, simply Click the "Copy Image to Clipboard" button. The following Click method is executed with this button is clicked:

Sub cmdCopyImage_Click()

  XferData.SetPicture BitmapSource.GetPicture

End Sub

This method uses the Bitmap GetPicture method, which gets the current bitmap image as an object and passes it to the XferData's SetPicture method. This copies the picture from the Envelop Bitmap object to the Windows Clipboard.


Testing the Application

The simplest way to test the sample Clipboard program is to open the Windows Notepad and PaintBrush applications.

To test the transfer of text from Envelop:

1.	Enter some text into the sample TextBox

2.	Click the "Copy Text to Clipboard" button.

3.	Now click in the Notepad window and select the Edit/Paste menu command. You should see the information you entered in the Envelop sample application.

To test the transfer of text to Envelop:

1.	While in the Notepad window, enter some new text.

2.	Select this text and select the Edit/Copy menu command.

3.	Now return to the Evelop sample and click the "View Text in Clipboard" button. You should see the Notepad selection in the textbox.

To test the transfer of graphic information to Envelop:

1.	Use Paintbrush to create some design.

2.	Then copy the image from Paintbrush onto the Clipboard by selecting the Edit/Copy menu command.

3.	To see the image, click the "View Image in Clipboard" button in the Envelop form.

To test the transfer of graphic information from Envelop:

1.	Use the File Manager to drag a bitmap file onto the Envelop Image control. The image should appear immediately.

2.	Click the "Copy Image to Clipboard" button.

3.	Now go to the Paintbrush window and click the Edit/Paste menu command to see the image.


Drag and Drop Bitmap Files

Another way of transferring graphics information into our Envelop sample is to drag a bitmap filename from the File Manager and drop it onto the form's Image control. This functionality is produced by a DragAndDrop method on the form as follows:

Sub DragAndDrop(source As XferData, x As Single, y As Single, state As Integer, effect As Long)

  If state == 3 Then

    Clip = source.GetData

    ClipInfo()

  ElseIf state == 4 Then

    BitmapSource.LoadType = "FileBased"

    BitmapSource.FileName = source.File

    RefreshBitmap

    Clip = BitmapSource.GetPicture

  End If

End Sub

If the file is dropped from the File Manager to any place on the form, the Bitmap object will have it's LoadType and FileName properties set. If the drag and drop was initiated from another source, the state will be set to 3 and the ClipInfo method will be executed. This method will display the dropped information in the sample form.