The information in this article applies to:
- Standard and Professional Editions of Microsoft Visual Basic for
Windows, versions 2.0 and 3.0
SUMMARY
Visual Basic programs can provide an Edit Copy command that puts text
onto the Clipboard along with the information needed to make a DDE link to
that text. Likewise, you can provide an Edit Paste command that extracts
the text and an Edit Paste Link command that extracts the DDE link
information, and then initiates a DDE conversation to the source text.
You can implement these clipboard operations using the GetText and SetText
format CF_LINK (&HBF00) with a string of the format:
Application|Topic!Item
The Visual Basic manuals and Help menu do not describe how to use the
Clipboard format CF_LINK.
NOTE: Visual Basic only supports Clipboard DDE operations for text.
MORE INFORMATION
When a Visual Basic DDE source program uses SetText with format CF_LINK,
the format of the string is exe|topic!item.
- exe is the value of App.EXEName.
- topic is a form's LinkTopic value.
- item is the Name of a control.
For example:
Project1|Form1!Text1
Step-by-Step Example
- Start Visual Basic or from the File menu, choose Open Project
(ALT, F, O) if Visual Basic is already running. Form1 is created.
- Change the form property LinkMode to 1 - Source.
- Place a text box named Text1 on the form.
- From the Window menu, choose Menu Design and create the following
menu structure.
Caption Name Indent Level
------------------------------------
Edit mEdit 0
Copy mCopy 1
Paste mPaste 1
Paste Link mPasteLink 1
- Enter the following code in the general declarations section:
Const CF_TEXT = 1
Const CF_LINK = &HBF00
- Enter the following code into the form:
Sub mEdit_Click ()
mCopy.Enabled = Text1.SelLength > 0
mPaste.Enabled = Clipboard.GetFormat(CF_TEXT)
mPasteLink.Enabled = Clipboard.GetFormat(CF_LINK)
End Sub
Sub mCopy_Click ()
Clipboard.Clear
Clipboard.SetText Text1.SelText, CF_TEXT
Clipboard.SetText "Project1|Form1!Text1", CF_LINK
End Sub
Sub mPaste_Click ()
Text1.LinkMode = 0 ' discontinue previous link
Text1.SelText = Clipboard.GetText(CF_TEXT)
End Sub
Sub mPasteLink_Click ()
Dim topic As String ' app|topic!item
Dim bang As Integer ' index of ! within topic
topic = Clipboard.GetText(CF_LINK)
bang = InStr(topic, "!")
If bang <> 0 Then
Text1.LinkMode = 0
Text1.LinkTopic = Mid$(topic, 1, bang - 1)
Text1.LinkItem = Mid$(topic, bang + 1)
On Error Resume Next
Text1.LinkMode = 1 ' automatic
If Err <> 0 Then
MsgBox "Cannot paste link"
End If
End If
End Sub
- From the File menu, choose Make EXE and click OK. This creates
PROJECT1.EXE.
- Launch PROJECT1.EXE twice so that two instances are running. Position
them so that you can see them both at the same time. In the first
instance, select the text in the text box, then from the Edit menu
choose copy. Switch to the second instance and from the Edit menu
choose Paste Link. Switch back to the first instance and change the
contents of the text box. These changes appear immediately in the
second instance.
|