Page 1 of 2
[Solved] Save content of ClipBoard
Posted: Wed Oct 17, 2012 3:29 pm
by TO7
Hi,
Is there a way to temporarily save the contents of the clipboard (picture or text), empty it, and restore it as if it had not emptied ??
Best regards
Re: Save content of ClipBoard
Posted: Wed Oct 17, 2012 3:55 pm
by jassing
TO7 wrote:Hi,
Is there a way to temporarily save the contents of the clipboard (picture or text), empty it, and restore it as if it had not emptied ??
Best regards
Yes, there's a whole section on clipboard functions in the help file..
Re: Save content of ClipBoard
Posted: Wed Oct 17, 2012 4:47 pm
by TO7
I know the crossplatform command
Code: Select all
a$ = GetClipboardText()
SetClipboardText("Hello")
SetClipboardText(a$)
Excuse me, i missing to say all contents
The problem is if the ClipBoard have other file (xls, exe, etc ..)
Re: Save content of ClipBoard
Posted: Wed Oct 17, 2012 5:17 pm
by doctorized
Re: Save content of ClipBoard
Posted: Wed Oct 17, 2012 5:52 pm
by TO7
Thanks for the link
Re: [Solved] Save content of ClipBoard
Posted: Wed Oct 17, 2012 7:59 pm
by rsts
TO7 wrote:Hi,
Is there a way to temporarily save the contents of the clipboard (picture or text), empty it, and restore it as if it had not emptied ??
Best regards
Hi,
This is NOT recommended, as it can involve saving and restoring MANY formats of possible UNKNOWN content/format.
You probably want to use the clipboard as an interim transfer or holding. What is it you need to do?
cheers
Re: [Solved] Save content of ClipBoard
Posted: Thu Oct 18, 2012 9:43 am
by TO7
You probably want to use the clipboard as an interim transfer or holding.
Yes exactely
What is it you need to do?
I want create a little universal snippet manager.
I need for that, to can sending to all IDE (PB Ide, Jabpbe, NotePad++, CodeBlock, VC++, VB, etc ...) a snippet.
The most simple way i have found is :
- Detecting the Hwnd of the IDE wanted
(Done)
- Detecting the type of data into it
(Not know how do that ??)
- Saving the content of the clipboard
- If Data = txt use Get/SetClipboardText() (Done)
- If Data = files use code of TsSoft (Done)
- Copy to the clipboard the snippet
(Done)
- Send to the IDE the snippet (Using keybd_event())
(Done)
- Works easily because the cursor is at the right place for writing the snippet
I have try SendMessage() but the text not writing at the place of the cursor (Name of class, name of the application changed, etc ..) 
- Reload the Clipboard with his old value, like if nothing passed
(Done)
Re: [Solved] Save content of ClipBoard
Posted: Thu Oct 18, 2012 9:56 am
by ts-soft
Changing the clipboard only as interaction from the user!
You can't restore the clipboard, the clipboard not only hold pictures, text or files!
Re: [Solved] Save content of ClipBoard
Posted: Thu Oct 18, 2012 10:11 am
by TO7
Aaaahh !!! Bad news

Perhaps i can sending text at the cursor of the IDE focused by another way ??
Re: [Solved] Save content of ClipBoard
Posted: Thu Oct 18, 2012 4:58 pm
by rsts
What triggers the action (of sending the snippit)?
How do you know the content you're sending?
cheers
Re: [Solved] Save content of ClipBoard
Posted: Fri Oct 19, 2012 7:57 am
by TO7
I try to reproduce the same manager template that PB.
It is very good, and I used every day.
Several problems, gave me the idea of trying to create one myself.
1 / I do not really like that found in freeware
2 / When using several machines and also several versions of PB, think to copy and synchronize the template file, for all versions have the same, it is binding.
3 / I also programming a little bit in C, and i would also have the same tools, when I am in code-block, PB, Visual C + +, Notepad + +, etc ...
Some have this function but less practical (VC + + As always simplicity crosoft).
Brief to reply to your question, it will be a window with a TreeGadget like PB and when I DblClic on an item, the text is sent by either the clipboard (I lost the contents as I was told TsSoft) sending CTRL + C and CTRL + V, or by KeybEvent () letter by letter.
I have not found other ways to send a text external application.
Because even in enumerating the classes in the application some have several tabs as Code-Block and the same class name.
And how do you know which tab has the cursor?????
Re: [Solved] Save content of ClipBoard
Posted: Sun Mar 10, 2019 10:45 am
by Dude
This topic is marked as "Solved" but I see no solution? I'm looking for a way to save most clipboard content and restore it later, too. Because we all know the clipboard can hold plain text, rich text, images, sounds, files, etc. I assume I just need to test all common clipboard data types (the ones I just mentioned) to see if they exist in the clipboard, and save them as a binary file first for re-copying back into the clipboard later?
Re: [Solved] Save content of ClipBoard
Posted: Sun Sep 01, 2024 2:18 pm
by Zapman
[Edit 20/09/21] See bellow a more recent version of the proposed code.
Re: [Solved] Save content of ClipBoard
Posted: Tue Sep 03, 2024 10:11 am
by drgolf
Hello Zapman (sorry i am french user so, my english is approximative)
With PB 6.12 B3 x64 i have an error with debuger (l'executable de debogage se ferme de façon inattendue)
Work well in x86.
Any clue ?
Re: [Solved] Save content of ClipBoard
Posted: Thu Sep 12, 2024 5:30 pm
by zapman*
Hi, DrGolf,
I revised the procedures to make them more robust:
Code: Select all
; ***************************************************
;
; Save and restore Clipboard content
; From Zapman helped by ChatGPT
; Windows Only
; PB 6.11 - Sept 2024
; Structure pour stocker les données du presse-papier
Structure ClipboardData
format.l
Data.i ; HGLOBAL
EndStructure
; Déclaration de la liste en tant que Global
Global NewList ClipboardDataList.ClipboardData()
;
; Fonction pour cloner les données du presse-papier
Procedure CloneClipboardData()
If OpenClipboard_(#Null)
Protected cfFormat = 0
Protected hData, hDataClone
Protected dataSize, *pOriginal, *pClone
; Parcourir les formats disponibles dans le presse-papier
OleFlushClipboard_()
Repeat
format = EnumClipboardFormats_(format)
If format
hData = GetClipboardData_(format)
If hData
; Duplicate the data.
; OleDuplicateData is able to duplicate hBitmap, hGlobal, hEnhMetaFile And hMetaFilePict.
TempHGlobal = OleDuplicateData_(hData, format, #Null)
If TempHGlobal
AddElement(ClipboardDataList())
ClipboardDataList()\format = format
ClipboardDataList()\data = TempHGlobal
Else
Debug "Unable to dupplicate clipboard data."
EndIf
EndIf
EndIf
Until format = 0
;
CloseClipboard_()
EndIf
EndProcedure
; Fonction pour restaurer les données du presse-papier
Procedure RestoreClipboardData()
If OpenClipboard_(#Null)
EmptyClipboard_()
;
; Restaurer les données du presse-papier
ForEach ClipboardDataList()
SetClipboardData_(ClipboardDataList()\format, ClipboardDataList()\data)
Next
CloseClipboard_()
EndIf
EndProcedure
;
Procedure ReleaseClipboardData(hData, Format)
;
Protected stgm.StgMedium, Tymed
;
Select Format
Case #CF_BITMAP, #CF_DSPBITMAP
Tymed = #TYMED_GDI ; Bitmap : gestion par GDI
Case #CF_ENHMETAFILE
Tymed = #TYMED_ENHMF ; Metafichier amélioré
Case #CF_METAFILEPICT
Tymed = #TYMED_MFPICT ; Metafichier classique
Default
Tymed = #TYMED_HGLOBAL ; Utiliser TYMED_HGLOBAL par défaut.
EndSelect
stgm\tymed = Tymed
stgm\hGlobal = hData
ReleaseStgMedium_(@stgm)
EndProcedure
;
; Fonction pour libérer la mémoire allouée
Procedure FreeClipboardData()
ForEach ClipboardDataList()
ReleaseClipboardData(ClipboardDataList()\data, ClipboardDataList()\format)
Next
ClearList(ClipboardDataList())
EndProcedure
; Exemple d'utilisation
CloneClipboardData()
SetClipboardText("essai")
; Restaurer le presse-papier
RestoreClipboardData()
; Libérer la mémoire allouée
FreeClipboardData()