WinClip is a clipboard manipulation class which allow you to do a bit more than the common ahk clipboard can
intended for:
[*:3kwk6bth] AHK_L unicode x32/x64
Download
Documentation
include WinClipAPI.ahk before WinClip.ahk!
Features:
[*:3kwk6bth] Change clipboard directly or operate on in-memory copy of it
[*:3kwk6bth] Ready-to-use methods to keep and maintain any number of clipboards at once
[*:3kwk6bth] Big number of functions to get different types of data from clipboard
[*:3kwk6bth] Possibility to get/change text on clipboard without touching other formats
[*:3kwk6bth] Easy way to get picture from clipboard and use it on your needs
[*:3kwk6bth] And other cookies...
Tips:
[*:3kwk6bth]You can use Markdown2HTML.ahk from fincs' GenDocs v3 viewtopic.php?p=555703#p555703 script to transform Markdown text to html format + WinClip.SetHTML(html) to be able to paste it directly in say your Office documents or an rich text email.
Full list of methods:
Snap( ByRefdata ) Restore( ByRefdata ) Clear() GetFormats() Save( filePath ) Load( filePath ) Copy() Paste( plainText = "" ) GetFiles() SetFiles( files, isCut = 0 ) AppendFiles( files, isCut = 0 ) GetBitmap() SetBitmap( bitmap ) SaveBitmap( filePath, format ) GetText() SetText( textData ) AppendText( textData ) GetHTML() SetHTML( html, source = "" ) IsEmpty() HasFormat( fmt )
Here is a small example of how to use it in the similar way you do with common ahk's "clipboardall" and "clipboard":
Getting data from clipboard:
clipData := clipboardall clipSize := WinClip.Snap( clipData )Restoring it up:
clipboard := clipData bytesRestored := WinClip.Restore( clipData )Getting plain text from clipboard:
plainText = %clipboard% plainText := WinClip.GetPlainText() filesList := WinClip.GetFilesList()Well, if you don't need anything besides that, it's best to keep up with standard clipboard.
Here is what it can do above basic stuff:
Get html format:
rawHTML := WinClip.GetHTML()
Get all formats currently on clipboard:
objFormats := WinClip.GetFormats() list = for nFmt, params in objFormats { ; format_number : format_name : data_size : data_size again ; the "buffer" is an object member containing actual format data list .= "`n" nFmt " : " params.name " : " params.size " : " params.GetCapacity( "buffer " ) } msgbox % list
GetBitmap and use it as picture in GUI:
;copy any picture first hBitmap := WinClip.GetBitmap() Gui, Add, Picture,% "hwndPicHwnd +" SS_BITMAP := 0xE SendMessage,% STM_SETIMAGE := 0x0172,% IMAGE_BITMAP := 0,% hBitmap,, ahk_id %PicHwnd% DllCall("DeleteObject", "Ptr", hBitmap ) Gui, Show, w1000 h700
Set or append text without changing whole clipboard into plain text:
WinClip.SetText( "hey, you!" ) WinClip.AppendText( "`nand you!" )
+ Copy, Paste, Clear methods.
!!! Make attention, that data from clipboardall, and WinClip.Snap() is not compatible
Another part of the WinClip class is the all the same function with "i" prefix which work with instantiated copy of WinClip class. It allows you to manipulate with in-memory copy of clipboard without changing the main one. Or you can just keep any number of different clipboards. Prefect for clipboards managers kind.
Here is an example:
wc := new WinClip clipSize := wc.iSnap() ;copies clip data into inner buffer for later using wc.Clear() ;clears Windows clipboard bytesRestored := wc.iRestore() ;restores data back to clipboards
All this described better in documentation
test.ahk inside downloadable .zip also offer some easy tutorial survey
Update 20/03/2012
Fixed SetHTML() function to use UTF-8
Update 7/02/2012
Added following methods to retrieve or set RTF format:
GetRTF(),iGetRTF
SetRTF( text ),iSetRTF( text )
Update 31/01/2012
Class name shortened to WinClip
all functions used by WinClip moved to another class, so you don't need to care about any similar you may have in your script (you must inlcude WinClipAPI.ahk first though )
Methods added ( check documentation for info ):
SetHTML,iSetHTML
iSetData
IsEmpty,iIsEmpty
HasFormat,iHasFormat
SaveBitmap,iSaveBitmap
Update 12/20/2011
Renamed methods:
GetPlainText() -> GetText()
iGetPlainText() -> iGetText()
GetFilesList() -> GetFiles()
iGetFilesList() -> iGetFiles()
Added methods:
SetFiles( files, isCut = 0 )
iSetFiles( .. )
AppendFiles( .. )
iAppendFiles( .. )
SetBitmap( bitmapPath or hBitmap )
iSetBitmap( .. )
iGetData( Data )
WinClipboard.Paste( plainText = "" ) method now can be called with parameter to paste raw text without changing actual clipboard data (iPaste does not support this)
Improved Copy/Paste methods so they work more reliable/faster now
Functiona added to WinClipboard_foos.ahk:
RemoveDubls
RegisterClipboardFormat
GetOpenClipboardWindow
StrSplit