Sign in to follow this  
Followers 0
PowerCat

ClipGet and ClipPut with MS Word formatting.

4 posts in this topic

#1 ·  Posted (edited)

I'm writing a small app that will monitor the clipboard and modify some strings when certain conditions are met.

I'm running into the issue that whenever it's running, it'll always strip every formatting that the string contained.

Open MS Word (or wordpad)

Write a line and then put a coloured letter, a bold and an underlined letter.

Copy that string and try any of the 3 "clipput" function. The string will be in black and lose all formatting.

Any known way to retain this, or at least skip the clip operation if my string contains formatting characters?

#include <Clipboard.au3>

$clip1 = _ClipBoard_GetData()
$clip2 = _ClipBoard_GetDataEx()
$clip3 = ClipGet()

;_ClipBoard_SetData($clip1)
;_ClipBoard_SetDataEx($clip2)
;ClipPut($clip3)
Edited by PowerCat

Share this post


Link to post
Share on other sites



I'm not sure how the clipboard functions are implemented by AutoIt, that is something for the devs to comment on but have a read of http://msdn.microsoft.com/en-us/library/ms649013%28v=vs.85%29.aspx.

When the content of the clipboard is pasted into another window, the window retrieves data in the most descriptive format it recognizes. If the window recognizes RTF, the corresponding data is pasted into the document. Otherwise, the text data is pasted into the document and the formatting information is lost.

Try using clipget to get some formatted text then manually paste to ensure clipput is the issue.


Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Share this post


Link to post
Share on other sites

I might be wrong cause it seems that _ClipBoard_SetDataEx() will preserve it. Further tests will be necessary :)

Share this post


Link to post
Share on other sites

After looking at Clipboard.au3 you appear correct.

Taken from Clipboard.au3.

More details are described in the _ClipBoard_GetData and _ClipBoard_SetData comments in the UDF.

; #FUNCTION# ====================================================================================================================
; Name...........: _ClipBoard_SetDataEx
; Description ...: Places data on the clipboard in a specified clipboard format
; Syntax.........: _ClipBoard_SetDataEx(ByRef $hMemory[, $iFormat = 1])
; Parameters ....: $hMemory     - Handle to the data in the specified format.  This parameter can be NULL, indicating that the
;                  +window provides data in the specified clipboard format upon request.  If a window delays rendering, it must
;                  +process the $WM_RENDERFORMAT and $WM_RENDERALLFORMATS messages.  If this function succeeds, the system owns
;                  +the object identified by the $hMemory parameter.  The application may not write to or free the data once
;                  +ownership has been transferred to the system, but it can lock and read from the data until the _ClipBoard_Close
;                  +function is called.  The memory must be unlocked before the clipboard is closed.  If the $hMemory parameter
;                  +identifies a memory object, the object must have been allocated using the function with the $GMEM_MOVEABLE
;                  +flag.
;                  $iFormat     - Specifies a clipboard format:
;                  |$CF_TEXT            - Text format
;                  |$CF_BITMAP          - Handle to a bitmap (HBITMAP)
;                  |$CF_METAFILEPICT    - Handle to a metafile picture (METAFILEPICT)
;                  |$CF_SYLK            - Microsoft Symbolic Link (SYLK) format
;                  |$CF_DIF             - Software Arts' Data Interchange Format
;                  |$CF_TIFF            - Tagged image file format
;                  |$CF_OEMTEXT         - Text format containing characters in the OEM character set
;                  |$CF_DIB             - BITMAPINFO structure followed by the bitmap bits
;                  |$CF_PALETTE         - Handle to a color palette
;                  |$CF_PENDATA         - Data for the pen extensions to Pen Computing
;                  |$CF_RIFF            - Represents audio data in RIFF format
;                  |$CF_WAVE            - Represents audio data in WAVE format
;                  |$CF_UNICODETEXT     - Unicode text format
;                  |$CF_ENHMETAFILE     - Handle to an enhanced metafile (HENHMETAFILE)
;                  |$CF_HDROP           - Handle to type HDROP that identifies a list of files
;                  |$CF_LOCALE          - Handle to the locale identifier associated with text in the clipboard
;                  |$CF_DIBV5           - BITMAPV5HEADER structure followed by bitmap color and the bitmap bits
;                  |$CF_OWNERDISPLAY    - Owner display format
;                  |$CF_DSPTEXT         - Text display format associated with a private format
;                  |$CF_DSPBITMAP       - Bitmap display format associated with a private format
;                  |$CF_DSPMETAFILEPICT - Metafile picture display format associated with a private format
;                  |$CF_DSPENHMETAFILE  - Enhanced metafile display format associated with a private format
; Return values .: Success      - The handle to the data
;                  Failure      - 0
; Author ........: Paul Campbell (PaulIA)
; Modified.......:
; Remarks .......: The $iFormat parameter can identify a registered clipboard format, or it can be one of the standard clipboard
;                  formats. If an application calls this function in response to $WM_RENDERFORMAT or $WM_RENDERALLFORMATS, the
;                  application should not use the handle after this function has been called.  If an application calls _ClipBoard_Open
;                  with a NULL handle, _ClipBoard_Empty sets the clipboard owner to NULL; this causes this function to fail.
; Related .......: _ClipBoard_Empty, _ClipBoard_GetData, _ClipBoard_Open, _ClipBoard_SetData
; Link ..........: @@MsdnLink@@ SetClipboardData
; Example .......: Yes
; ===============================================================================================================================
Func _ClipBoard_SetDataEx(ByRef $hMemory, $iFormat = 1)
    Local $aResult = DllCall("user32.dll", "handle", "SetClipboardData", "uint", $iFormat, "handle", $hMemory)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[0]
EndFunc   ;==>_ClipBoard_SetDataEx

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0