Announcement

Collapse
No announcement yet.

Free Memory for Pasting 64 chars to Clipboard

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Free Memory for Pasting 64 chars to Clipboard

    Ive been reading Poffs about pasting text to the clipboard. I see some great examples that i think are more complicated than I need for pasting a short file name to the clipboard.

    Do I need to free enough memory for this first?
    Does anyone have a really simple example available for pasting text from a PB app to the clipboard (for pasting into the editor later)

    ------------------
    Kind Regards
    Mike

  • #2
    These will be in CCSDLG32.DLL, coming soon to a website near you....


    Code:
    Declare Function CCSClipboard_GetFormat(ByVal cfFormat As Dword)  As Long
    Declare Function CCSClipboard_SetText(ByVal Text As String)  As Long
    Declare Function CCSClipboard_GetText ()  As String
    Declare Function CCSClipboard_SetData (ByVal hData As Dword, ByVal cfFormat As Integer)  As Long
    Declare Function CCSClipboard_GetData(ByVal cfFormat As Dword)  As Dword
    '
    '
    '
    '
    '------------------------------------------------------------------------------------------
    '==============<CLIPBOARD STUFF>===========================================================
    '------------------------------------------------------------------------------------------
    
    Function CCSClipboard_GetFormat Alias "CCSClipboard_GetFormat"(ByVal cfFormat As Dword) Export As Long
        Function = IsClipboardFormatAvailable(CfFormat) <> 0
    End Function
    
    '------------------------------------------------------------------------------------------
    
    Function CCSClipboard_SetText Alias "CCSClipboard_SetText"(ByVal Text As String) Export As Long
    Local lpMem As Asciiz Ptr
    Local hMem  As Dword
        ' Allocate global memory block
        hMem  = GlobalAlloc(%GHND, Len(Text) + 1)
        ' lock it and get pointer to memory location
        lpMem = GlobalLock(hMem)
        ' copy text into memory object
        @lpMem = Text
        ' unlock the memory object
        GlobalUnlock hMem
        ' add text to the clipboard
        OpenClipboard 0
        EmptyClipboard
        SetClipboardData %CF_TEXT, hMem
        CloseClipboard
        GlobalFree hMem
    End Function
    
    '----------------------------------------------------------------------------------------
    Function CCSClipboard_GetText Alias "CCSClipboard_GetText"() Export As String
    Local hMem  As Dword
    Local lpMem As Asciiz Ptr
    If CCSClipboard_GetFormat(%CF_TEXT) Then
        ' open the clipboard
        OpenClipboard 0
        ' Get memory object of clipboard text
        hMem = GetClipboardData(%CF_TEXT)
        ' lock it and get a pointer
        lpMem = GlobalLock(hMem)
        ' assign the data to our function return value
        Function = @lpMem
        ' release the memory object
        GlobalUnlock hMem
        ' close the clipboard
        CloseClipboard
        GlobalFree hMem
    Else
        Function = ""
    End If
    End Function
    '----------------------------------------------------------------------------------------
    
    '  TITLE: Clipboard_SetData
    '   DESC: Puts a data object into the clipboard.
    ' SYNTAX: Clipboard_SetData hData, Format
    '  NOTES: The application must not use the hData handle once it has called the
    '         Clipboard_SetData procedure.
    '
    Function CCSClipboard_SetData Alias "CCSClipboard_SetData"(ByVal hData As Dword, ByVal cfFormat As Integer) Export As Long
    ' add data to the clipboard
    OpenClipboard 0
    EmptyClipboard
    SetClipboardData cfFormat, hData
    CloseClipboard
    Function = %TRUE
    End Function
    '----------------------------------------------------------------------------------------
    '  TITLE: Clipboard_GetData
    '   DESC: Get a data object from the clipboard.
    ' SYNTAX: hData = Clipboard_GetData(format)
    '         'format' specifies one of the following clipboard formats:
    '
    '         %CF_BITMAP    Bitmap (.BMP file)
    '         %CF_METAFILE  Metafile (.WMF file)
    '         %CF_DIB       Device-independent bitmap
    '         %CF_PALETTE   Color palette
    '
    '----------------------------------------------------------------------------------------
    Function CCSClipboard_GetData Alias "CCSClipboard_GetData"(ByVal cfFormat As Dword) Export As Dword
    Local hSource  As Dword
    Local hDest    As Dword
    Local hSize    As Dword
    Local lpSource As Dword
    Local lpDest   As Dword
    
        ' add data to the clipboard
        OpenClipboard 0
        hSource  = GetClipboardData(cfFormat)
        CloseClipboard
    
        ' Get size of data object
        hSize    = GlobalSize(hSource)
        ' allocate a new data object
        hDest    = GlobalAlloc(%GHND, hSize)
        ' get pointers to source and destination objects
        lpSource = GlobalLock(hSource)
        lpDest   = GlobalLock(hDest)
        ' copy the data from the source to the destination  hmemcpy lpDest, lpSource, hSize
        ' unlock both data objects  GlobalUnlock hSource  GlobalUnlock hDest
        ' return handle to the new data object
        Function = hDest
    End Function
    ------------------
    Scott
    Scott Turchin
    MCSE, MCP+I
    http://www.tngbbs.com
    ----------------------
    True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

    Comment

    Working...
    X