Click here to Skip to main content
15,896,063 members
Articles / Programming Languages / C++
Article

Multiple Clipboard Macros

Rate me:
Please Sign up or sign in to vote.
1.00/5 (1 vote)
24 Jan 2001CPOL 45K   10   2
Three simple macros that work together to add multiple clipboard functionality to Microsoft Visual C++.

These three simple macros work together to add multiple clipboard functionality to Microsoft Visual C++. Along with macros in the macro file you will find a couple of global variables. The most important one is a buffer used to collect up to 5 selections. MCopy adds the current selection to the end of the buffer. MPaste pastes the last copied string to the document and makes it selected. If you then execute MPaste again it takes another string from the buffer and replaces the previously pasted string. You can execute MPaste as many times as you want until you decide which selection to keep. And finally MClear resets the buffer. Enjoy!

VB.NET
'============== Multiple Clipboard Macros By Michael Pelts ========================

Dim buffer(4)
Dim nCopy
nCopy = 0
Dim nPaste
nPaste = 0
Dim nBufferSize
nBufferSize = 0

Sub MCopy ()
'DESCRIPTION: Multiple clipboard - copy
    if ActiveDocument Is Nothing Then
        Exit Sub
    elseif ActiveDocument.Type <> "Text" Then
        Exit Sub
    elseif Len(ActiveDocument.Selection) > 3060 Then
        MsgBox("Too long selectection")
        Exit Sub
    elseif Len(ActiveDocument.Selection) = 0 Then
        Exit Sub
    End If

    ActiveDocument.Selection.Copy
    buffer(nCopy) = ActiveDocument.Selection

    nPaste = nCopy
    nCopy = nCopy + 1
    
    if nCopy > 4 then 
        nCopy = 0
    End If

    if nBufferSize < 5 then
        nBufferSize = nBufferSize + 1
    end if
End Sub

'==================================================================

Sub MPaste ()
'DESCRIPTION: Multiple clipboard - paste
    ' Be sure active document is a text document
    if ActiveDocument Is Nothing Then
        Exit Sub
    elseif ActiveDocument.Type <> "Text" Then
        Exit Sub
    End If

    if nBufferSize = 0 then
        MsgBox("Empty buffer")
        Exit Sub
    End If

    ActiveDocument.Selection = ""
    Dim curCol
    Dim curLine
    curCol = ActiveDocument.Selection.CurrentColumn
    curLine = ActiveDocument.Selection.CurrentLine
    
    'get rid of new lines to obtain actulal string lenght
    tempPasteStr = buffer(nPaste)
    tempPasteStr = Replace(tempPasteStr, string(1, vbCr), "")

    Dim pasteStrLen
    pasteStrLen = Len(tempPasteStr)
    ActiveDocument.Selection = buffer(nPaste)

    if pasteStrLen < 400 then
        ActiveDocument.Selection.MoveTo curLine, curCol
        ActiveDocument.Selection.CharRight dsExtend, pasteStrLen
    end if
    
    nPaste = nPaste + 1    
    if nPaste >= nBufferSize then 
        nPaste = 0
    End If
End Sub

'==================================================================

Sub MClear ()
'DESCRIPTION: Resets the buffer.
    nCopy = 0
    nPaste = 0
    nBufferSize = 0
End Sub


'==================================================================

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States

Comments and Discussions

 
GeneralMultiple Clipboard Pin
K.Stein2-Jan-01 20:59
K.Stein2-Jan-01 20:59 
GeneralRe: Multiple Clipboard Pin
21-Feb-01 0:58
suss21-Feb-01 0:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.