Announcement

Collapse
No announcement yet.

Clipboard

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

  • Dale Yarker
    replied
    Or right click on page, and select "View page source".

    Leave a comment:


  • Steve Hutchesson
    replied
    While I don't have much use for it, if you want the exposed HTML, type the URL into a rich text editor then open the file and it will be loaded into the rich text editor.

    Leave a comment:


  • Dave Biggs
    replied
    Depending on the source, it's probably necessary to note that fragments copied to the Clipboard may comprise mark up language that refers to style / font definitions / file locations etc that are not part of the fragment.

    This might result in unexpectedly lost features, images, colours and so on when the snippet is rendered on the destination, even when the destination is appropriate for the type of data?

    Leave a comment:


  • Stuart McLachlan
    replied
    Originally posted by Kerry Farmer View Post
    Thanks Dave and Stuart

    But windowskey and v just shows the start of the copied document history in plain font!!!
    Yep, the history just shows the start of the plain text version of the clipboard content (in a simple, text only listbox), but it stores all variants in full. When you use it to paste a saved clip, the application will still use the "richest" one it can handle. So if you copy fancy formatted text from a brower or Word, you only see the start of the text in black and white, but if you paste back into Word or Outlook, you will get the full HTML version that you originally copied.

    Leave a comment:


  • Kerry Farmer
    replied
    Thanks Dave and Stuart

    But windowskey and v just shows the start of the copied document history in plain font!!!

    Leave a comment:


  • Stuart McLachlan
    replied
    Originally posted by Dave Biggs View Post
    FYI Windows10 has a built in Clipboard history viewer, accessible via WindowsKey + 'v' when enabled in Settings.

    That can be used to assemble data on a destination from multiple earlier clips.
    Which is quite possibly the simple solution to Kerry's original requirement

    FWIW, it was greyed out in Settings when I looked for it.
    I had to set HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\System\AllowClipboardHistory to DWORD = 1 and reboot before I could enable it in Settings.

    Leave a comment:


  • Dave Biggs
    replied
    FYI Windows10 has a built in Clipboard history viewer, accessible via WindowsKey + 'v' when enabled in Settings.

    That can be used to assemble data on a destination from multiple earlier clips.

    Leave a comment:


  • Kerry Farmer
    replied
    Thanks Stuart

    I am indeed starting to understand

    Kerry

    Leave a comment:


  • Stuart McLachlan
    replied
    Originally posted by Kerry Farmer View Post
    OK - forgive my naivety

    I often (nearly every day!) copy from Word files to Outlook with no problem (except if you use the middle justify and right justify options which can be a bit messy, or any system of not left justifying). The colours and bolds and font sizes and types all are correctly copied. I copy to the email address, the subject and the message. When you post to the email address, it copies down to the first end of line and takes out all the editing
    That's not techincally correct. It doesn't "take out all the editing", it just pastes the part of the plain text version up to the first CRLF that is on the clipboard and not the HTML version
    That is completely logical. Since email headers have to be a single line and plain text (you can't uses fonts/colours etc) Outlook only pastes part of one of the plain TEXT versions of the data on the clipboard into the header blocks (I haven't tested, but it probably pastes the CF_UNICODE version and converts that to UTF-8 when it sends the email IAW RFC 6532 )

    The main message editing windows uses HTML so Outlook will paste the full CF_HTML content (not exactly, just the "fragment" part, see Rod's last image ).
    So are we saying that PB has a limited implementation of copy in the Clipboard instruction?
    Yes.

    "The Windows ClipBoard provides support for the transfer of various types of data between applications, or even different parts of a single application. The concept is simple -- save some data on the ClipBoard and retrieve it later. In most cases, it's just used to transfer plain text, so the PowerBASIC CLIPBOARD statement concentrates on the common data formats."

    Which is a subtle way of saying: "The CLIPBOARD functions only work with plain text (ANSI STRINGs or UTF-16 WSTRINGs or a Bitmap"

    And are we saying that we cannot get around it?
    You can't get round it using PB's intrinsic CLIPBOARD functions.
    But as explained in Post 6 and demonstrated in Post 8, you can copy HTML formatting from and to the clipboard using standard Win32 API functions (the demo uses PB's intrinsic GLOBALMEM functions rather than the equivalent GlobalXxxxxx API functions)

    A similar approach can be taken for ANY form of data as long as you use RegisterClipboardFormat first if it's not one of the "standard clipboard formats".
    https://docs.microsoft.com/en-us/win...pboard-formats

    Leave a comment:


  • Kerry Farmer
    replied
    OK - forgive my naivety

    I often (nearly every day!) copy from Word files to Outlook with no problem (except if you use the middle justify and right justify options which can be a bit messy, or any system of not left justifying). The colours and bolds and font sizes and types all are correctly copied. I copy to the email address, the subject and the message. When you post to the email address, it copies down to the first end of line and takes out all the editing (a very useful function because if you put the subject as the first line of the message, you can then paste the same content to both subject and message)

    So are we saying that PB has a limited implementation of copy in the Clipboard instruction?

    And are we saying that we cannot get around it?

    Thanks again



    Kerry

    Leave a comment:


  • Rod Macia
    replied


    Originally posted by Kerry Farmer View Post
    I am pasting into an Outlook email - an about to be sent email. I am struggling to see why that is relevant!
    Where you copy From, and what you paste To is very relevant. The program you copy from will create a series of clipboard versions, some determined by the programmer(s) of that program, some automatically by the operating system.

    In your case we are guessing that you are copying from a web page (aka a browser program - you did not say which, they don't all save the same formats but some overlap)

    Here is the same content Copied to Clipboard from different programs. You will notice that some programs offer many more clipboard formats, it becomes the programmers responsibility to chose the required format.

    PB build in clipboard functions cover a small subset (like Dave mentioned) the ones that are almost always there. But as Stuart has shown you can use the API to get the others if needed.

    From Notepad++

    Click image for larger version  Name:	Clip3.png Views:	0 Size:	31.3 KB ID:	818042


    From Microsoft Word

    Click image for larger version  Name:	Clip4.png Views:	0 Size:	82.5 KB ID:	818043

    From Firefox Browser

    Click image for larger version  Name:	Clip2.png Views:	0 Size:	83.4 KB ID:	818044

    Microsoft Edge

    Click image for larger version  Name:	Clip5.png Views:	0 Size:	61.9 KB ID:	818045

    Leave a comment:


  • Stuart McLachlan
    replied
    Originally posted by Kerry Farmer View Post
    I am pasting into an Outlook email - an about to be sent email. I am struggling to see why that is relevant!
    It's relevant because you didn't tell us what you were trying to paste into. Only some applications can accept CF_HTML clipboard formats. For example, you can't paste Rich Text (HTML) into Wordpad even though it understands RichText (RTF)/.

    And if it's any other editor that only understand RTF, you will only get the unformatted text (i.e. any editor based on a RichEdit control.)

    Try copying something from your browser and then pasting it into your Outlook email editor and Wordpad - you well see very different results.

    Leave a comment:


  • Kerry Farmer
    replied
    I am pasting into an Outlook email - an about to be sent email. I am struggling to see why that is relevant!

    Leave a comment:


  • Stuart McLachlan
    replied
    OK, that was an interesting exercise.

    1. Save any CF_HTML that is in the clipboard when the application is opened, to a UTF-8 string
    2. Copy some text to the clipboard, removing the CF_HTML in the process.
    3. Copy the saved UTF8 string back to CF_HTML on the the clipboard.

    (It can easily be augmented with a GUI that lets you save and replace the clipboard HTML at any time.
    I might knock one up and put it in the Suurce Code forum later )


    '
    Code:
    #COMPILE EXE "GetClipHTML"
    #DIM ALL
    #DEBUG ERROR ON
    #DEBUG DISPLAY ON
    '%Unicode = 1
    #INCLUDE "win32api.inc"
    
    FUNCTION PBMAIN() AS LONG
        LOCAL wsHTML,wsTmp AS WSTRING
        LOCAL sHTML AS STRING
        LOCAL lResult AS LONG
    
        'Get Clipboard HTML if there is any
        lResult =  GetHTML(sHTML)
        IF lResult > 0 THEN
            ? "Error: " & STR$(lResult) & "  getting Clipboard HTML"
            EXIT FUNCTION
        END IF
        wsHTML = UTF8TOCHR$(sHTML)
        ? "HTML from CLipboard:" & $LF & $LF & wsHTML
    
        'Replace the clipboard data with some text
        wsTmp = "Some Wide Text"
        CLIPBOARD RESET
        CLIPBOARD SET TEXT wsTmp
        ? "Clipboard contains different text now - paste it somewhere and then click OK"
    
        'Put the original UTF-8 back on the clipboard.
        lResult = SaveHTML(sHTML)
        IF lResult = 0 THEN
            ? "HTML back on clipboard - try pasting it into a document that supports that format."
        ELSE
            ? "Error " & STR$(lresult) & " setting clipboard HTML"
        END IF
    END FUNCTION
    
    FUNCTION GetHTML(sHTMLUTF8 AS STRING) AS LONG
        LOCAL lReturn,CF_HTML AS DWORD
        LOCAL lSize AS LONG
        LOCAL sPtr AS DWORD
        lReturn =  OpenCLipboard ( %NULL)
        IF lReturn = 0 THEN
            FUNCTION = 1 ' Can't open clipboard
            EXIT FUNCTION
        END IF
        CF_HTML = RegisterClipboardFormat("HTML format")
        IF CF_HTML = 0 THEN
            FUNCTION = 2 'Can't register format
            closeClipboard
            EXIT FUNCTION
        END IF
        lReturn = Getclipboarddata(CF_HTML)
        IF lReturn = 0 THEN
            FUNCTION = 3 'couldn't get HTML data
            closeclipboard
            EXIT FUNCTION
        END IF
        sPtr = GlobalLock(lreturn)
        IF sPtr <> 0 THEN
           lSize = globalsize(sPtr)
           IF lsize = 0 THEN
              FUNCTION =  4 'Zero length memory block?
              CloseClipboard
              EXIT FUNCTION
           END IF
           sHTMLUTF8 = PEEK$(sPtr,lSize)
        END IF
        CloseClipboard
    END FUNCTION
    
    FUNCTION SaveHTML(sHTMLUTF8 AS STRING) AS LONG
        LOCAL lReturn,lSize,CF_HTML AS DWORD
        LOCAL hMem AS DWORD
        lReturn =  OpenCLipboard (BYVAL 0)
        IF lReturn = 0 THEN
            FUNCTION = 1 ' Can't open clipboard
            EXIT FUNCTION
        END IF
        CF_HTML = RegisterClipboardFormat("HTML format")
        IF CF_HTML = 0 THEN
            closeClipboard
            FUNCTION = 2 'UNable to register format
            EXIT FUNCTION
         END IF
         lReturn = EmptyClipboard
         IF lReturn = 0 THEN
             closeClipboard
             FUNCTION = 3 ' unable to empty clipboard
             EXIT FUNCTION
         END IF
         GLOBALMEM ALLOC LEN(sHTMLUTF8) TO lReturn
         IF lReturn = 0 THEN
             FUNCTION = 4  'UNable to allocate global memory
             CloseClipboard
             EXIT FUNCTION
         END IF
         GLOBALMEM LOCK lReturn TO hMem
         IF hMem = 0 THEN
            FUNCTION = 5 'Unable to lock memory
            EXIT FUNCTION
         END IF
         POKE$ hMem,sHTMLUTF8
         lReturn = SetClipboardData( BYVAL CF_HTML,BYVAL hMem)
         closeclipboard
         IF lReturn = 0 THEN
             FUNCTION = 5 'UNable to Set Clipboard Data
             EXIT FUNCTION
         END IF
    END FUNCTION
    '
    Last edited by Stuart McLachlan; 1 Aug 2022, 06:07 AM.

    Leave a comment:


  • Stuart McLachlan
    replied
    Originally posted by Dave Biggs View Post

    But you do have the full API at your fingertips too!

    Are you looking to copy Rich Text to the clipboard / edit content then paste to your External Document( which can handle RTF) or ..?

    Maybe use API to get handles and SendMessage (Source) %WM_COPY .. edit in prog .. SendMessage (Destination) %WM_Paste.. ??
    Not RTF. It will be Rich Text with a space i.e. %CF_ HTML

    More importantly, %WM_Copy only copies the currently selected plain text as %CF_TEXT format from a textbox or combobox (Edit control), similarly %WM_Paste only pastes to the same type of controls and just plain text. (So not even UTF-16/WSTRING)
    (As I pointed out a couple of days ago when someone suggested using %WM_COPY to get the content of a Text Window. (TXT psuedo-object) )

    Leave a comment:


  • Stuart McLachlan
    replied
    Originally posted by Kerry Farmer View Post
    Dale - I am posting into an external document (it helps that I have two screens, so I can run my program on one screen and have an external doc on the other screen)
    You are missing the point. What application is the "external document" open in? Is it a Word document (.doc or .docx), a text editor (Notepad, Notepad++), Wordpad, or some other document creation application.

    I assume this is related to your copying from a web browser page discussed in an earlier thread and that you are pasting in MS Word..

    The "stuff" you copied from the browser will have been saved on the clipboard in several formats:

    %CF_HTML - the text and the HTHM markup (fonts, colours etc) - stored as UTF-8
    %CF_UNICODE - the text in UTF-16 (WSTRING) format - all the text characters will be stored, but none of the formatting
    %CF_TEXT - the text is saved as best WIndows can managed in single character ANSI text using your current code page/
    %CF_OEMTEXT - the text saved as best WIndows can manage in single character ANSI text using your default OEM code page.

    Your document application will use as the default the "richest" available format that it can handle (for Word, that is %CF_HTML), but may (like Word) give you the option to paste in less rich format such as "Text only"

    As Dave (and Help) says, the PB's CLIPBOARD functions are limited. Unfortunately, they don't handle the %CF_HTML text that you want to store in your application and retrieve later.
    You need to copy the %CF_HTML formatted text to and from a single byte character STRING using the appropriate API functions rather than PB's CLIPBOARD functions.

    https://docs.microsoft.com/en-us/win...opy-operations

    Note: Dave mentions "Rich Text" (with a space), that is actually HTML as opposed to "RICHTEXT" (no space) format aka RTF which is what MS used to use for email is still the default format for Wordpad and what is used in RichEdit controls. They should not be confused with each other

    Just as a matter of interest, Word and Excel now use XML (simlar to HTML) for their documents and Microsoft Access uses HTML for "rich text" format in textboxes.
    Last edited by Stuart McLachlan; 1 Aug 2022, 06:37 AM.

    Leave a comment:


  • Dave Biggs
    replied
    subset does not sound good!
    But you do have the full API at your fingertips too!

    Are you looking to copy Rich Text to the clipboard / edit content then paste to your External Document( which can handle RTF) or ..?

    Maybe use API to get handles and SendMessage (Source) %WM_COPY .. edit in prog .. SendMessage (Destination) %WM_Paste.. ??

    Leave a comment:


  • Kerry Farmer
    replied
    Thank

    Dave - subset does not sound good!

    Dale - I am posting into an external document (it helps that I have two screens, so I can run my program on one screen and have an external doc on the other screen)

    K

    Leave a comment:


  • Dale Yarker
    replied
    Kerry, are you pasting into a console?

    OEM, ANSI and Unicode are character sets. Nothing to do with formatting like bold or color.

    For text, use of WSTRINGs as normal.

    Cheers,

    Leave a comment:


  • Dave Biggs
    replied
    As you know. You can examine what is on the Clipboard at any time, for example by using a Free Clipboard Viewer..

    When you copy to the Clipboard, the source informs the operating system what formats the data are captured into.

    When you paste that data, the target informs the operating system which format is used.

    Eg If Rich Text is copied (it will be saved in several forms) Rich Text is available to paste into (say) Wordpad.
    ...... The same data is available in Plain Text form and would be pasted into Notepad.

    ANSI text to a ANSI control / variable

    UNICODE text into a Unicode control /variable.

    The Clipboard Statement available in PowerBASIC offers a limited (but useful) subset of the API options.

    You probably need to be specific about the source and eventual destination to get helpful suggestions
    Last edited by Dave Biggs; 31 Jul 2022, 09:34 PM.

    Leave a comment:

Working...
X