Announcement

Collapse
No announcement yet.

clipboard example code

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

  • clipboard example code

    I have searched the forum but can't find any sample code
    for storing some text into the clipboard. Ideas?

    ------------------

  • #2
    a search of the bbs gets a lot of hits for "clipboard".

    for example, http://www.powerbasic.com/support/pb...ad.php?t=22581

    ------------------
    lance
    powerbasic support
    mailto:[email protected]support[email protected]</a>
    Lance
    mailto:[email protected]

    Comment


    • #3

      I found some code somewhere quite a while back and modified it for my needs...

      Code:
      Function SetClipboardText Alias "SetClipboardText" (ByVal sText As String) Export As Long
        Local hData As Long, hGlob As Long
      ' ** Create a global memory object and copy the data into it
        hData = GlobalAlloc(%GMEM_MOVEABLE Or %GMEM_DDESHARE, Len(sText)+1)
        hGlob = GlobalLock(hData)
        Poke$ hGlob, sText + Chr$(0)
        GlobalUnlock hData
      ' ** Open the clipboard
        If IsFalse(OpenClipboard(%NULL)) Then
          GlobalFree hData
          Exit Function
        End If
      ' ** Paste the data into the clipboard
        EmptyClipboard
        Function = SetClipboardData(%CF_TEXT, hData)
        CloseClipboard
      End Function
      
      Function GetClipboardText Alias "GetClipboardText" () Export As String
       Local zPtr As Asciiz Ptr
       OpenClipBoard 0
       zPtr = GetClipboardData(%CF_TEXT)
       If zPtr <> 0 Then Function = @zPtr
       CloseClipboard
      End Function

      HTH!

      ------------------
      Kev G Peel
      KGP Software, Bridgwater, UK.
      mailto:[email protected][email protected]</A>
      kgpsoftware.com | Slam DBMS | PrpT Control | Other Downloads | Contact Me

      Comment


      • #4
        Related subject: Does anyone know how to copy both text and font data
        from a control, like a textbox? MS Charmap does some trick there, using
        plain textbox and when you copy the contents via Copy button, it also
        copies the font.

        Fiddled around with this once, but finally resorted to using Rich Edit
        instead. Would be fun to know how to do it with any control though..


        ------------------

        Comment


        • #5
          Borje --
          All is simple - MS products write some formats.
          Try to copy from Word and so on, and look results.
          Code:
             #Compile Exe
             #Dim All
             #Register None
             #Include "Win32Api.Inc"
          
             CallBack Function DlgProc
                Static hwndNextViewer As Long, nEvents As Long
                Local uFormat As Long, Msg As String, TmpAsciiz As Asciiz * %MAX_PATH
                Select Case CbMsg
                   Case %WM_INITDIALOG
                      hwndNextViewer = SetClipboardViewer(CbHndl)
                   Case %WM_CHANGECBCHAIN
                      If CbWparam = hwndNextViewer Then hwndNextViewer = CbLparam Else _
                      If hwndNextViewer <> 0 Then SendMessage hwndNextViewer, CbMsg, CbWparam, CbLparam
                   Case %WM_DESTROY
                      ChangeClipboardChain CbHndl, hwndNextViewer
                   Case %WM_DRAWCLIPBOARD
                      If OpenClipboard(CbHndl) Then
                         Incr nEvents
                         Msg = Msg + "Event #" + Format$(nEvents)
                         uFormat = EnumClipboardFormats(0)
                         While uFormat
                            TmpAsciiz = ""  
                            GetClipboardFormatName uformat, TmpAsciiz, SizeOf(TmpAsciiz)
                            Msg = Msg + $CRLF + "[" + Format$(uformat) + "] " + TmpAsciiz
                            uFormat = EnumClipboardFormats(uFormat)
                         Wend
                         CloseClipboard
                      End If
                      Control Set Text CbHndl, 101, Msg
                      SendMessage hwndNextViewer, CbMsg, CbWparam, CbLparam
                End Select
            End Function
          
            Function PbMain
               Local hDlg As Long
               Dialog New 0, "List of clipboard formats", ,, 220, 220, %WS_CAPTION Or %WS_SYSMENU, %WS_EX_TOPMOST To hDlg
               Control Add Label, hDlg, 101, "", 10, 10, 200, 200
               Dialog Show Modal hDlg Call DlgProc
            End Function
          [This message has been edited by Semen Matusovski (edited August 05, 2001).]

          Comment


          • #6
            Yes, once did similar viewer and MS Charmap copy is Rich text format,
            but question is how they do it. Remember I tried many things but never
            got it to work with standard textbox, so to save time, I decided to
            use Rich edit control instead. Have a feeling answer is very simple,
            but hard part is always to find out those simple answers.

            The fun thing with MS Charmap is, if to use right-click menu or Ctrl+C
            to copy from textbox, no font data is stored. Only when using copy button,
            which indicates they render the contents via special function somehow.

            Not important question - don't work with it anymore. Just wondered if
            anyone ever had stumbled upon this and solved the MS Charmap riddle..


            ------------------

            Comment

            Working...
            X