Microsoft KB Archive/106238: Difference between revisions
m (Text replacement - "<" to "<") |
m (Text replacement - "&" to "&") |
||
(One intermediate revision by the same user not shown) | |||
Line 47: | Line 47: | ||
== SUMMARY == | == 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 (& | 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: | ||
<div class="errormessage"> | <div class="errormessage"> | ||
Line 88: | Line 88: | ||
<li><p>Enter the following code in the general declarations section:</p> | <li><p>Enter the following code in the general declarations section:</p> | ||
<pre class="codesample"> Const CF_TEXT = 1 | <pre class="codesample"> Const CF_TEXT = 1 | ||
Const CF_LINK = & | Const CF_LINK = &HBF00 | ||
</pre></li> | </pre></li> | ||
<li><p>Enter the following code into the form:</p> | <li><p>Enter the following code into the form:</p> | ||
<pre class="codesample"> Sub mEdit_Click () | <pre class="codesample"> Sub mEdit_Click () | ||
mCopy.Enabled = Text1.SelLength | mCopy.Enabled = Text1.SelLength > 0 | ||
mPaste.Enabled = Clipboard.GetFormat(CF_TEXT) | mPaste.Enabled = Clipboard.GetFormat(CF_TEXT) | ||
mPasteLink.Enabled = Clipboard.GetFormat(CF_LINK) | mPasteLink.Enabled = Clipboard.GetFormat(CF_LINK) | ||
Line 114: | Line 114: | ||
topic = Clipboard.GetText(CF_LINK) | topic = Clipboard.GetText(CF_LINK) | ||
bang = InStr(topic, "!") | bang = InStr(topic, "!") | ||
If bang < | If bang <> 0 Then | ||
Text1.LinkMode = 0 | Text1.LinkMode = 0 | ||
Text1.LinkTopic = Mid$(topic, 1, bang - 1) | Text1.LinkTopic = Mid$(topic, 1, bang - 1) | ||
Line 120: | Line 120: | ||
On Error Resume Next | On Error Resume Next | ||
Text1.LinkMode = 1 ' automatic | Text1.LinkMode = 1 ' automatic | ||
If Err < | If Err <> 0 Then | ||
MsgBox "Cannot paste link" | MsgBox "Cannot paste link" | ||
End If | End If |
Latest revision as of 11:24, 21 July 2020
Article ID: 106238
Article Last Modified on 12/9/2003
APPLIES TO
- Microsoft Visual Basic 2.0 Standard Edition
- Microsoft Visual Basic 3.0 Professional Edition
- Microsoft Visual Basic 2.0 Professional Edition
- Microsoft Visual Basic 3.0 Professional Edition
This article was previously published under Q106238
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:
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.
Additional query words: docerr 3.00
Keywords: KB106238