[Solved] Save content of ClipBoard
[Solved] Save content of ClipBoard
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
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
Last edited by TO7 on Wed Oct 17, 2012 5:53 pm, edited 1 time in total.
Sorry but, Google translate is my friend 

Re: Save content of ClipBoard
Yes, there's a whole section on clipboard functions in the help file..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
Re: Save content of ClipBoard
I know the crossplatform command
Excuse me, i missing to say all contents
The problem is if the ClipBoard have other file (xls, exe, etc ..)

Code: Select all
a$ = GetClipboardText()
SetClipboardText("Hello")
SetClipboardText(a$)

The problem is if the ClipBoard have other file (xls, exe, etc ..)
Sorry but, Google translate is my friend 

- doctorized
- Addict
- Posts: 882
- Joined: Fri Mar 27, 2009 9:41 am
- Location: Athens, Greece
Re: Save content of ClipBoard
Take a look at: http://purebasic.fr/english/viewtopic.php?f=13&t=51592
It may be useful.
It may be useful.
Re: [Solved] Save content of ClipBoard
Hi,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
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
Yes exactelyYou probably want to use the clipboard as an interim transfer or holding.
I want create a little universal snippet manager.What is it you need to do?
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)
- 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 ..)
Last edited by TO7 on Thu Oct 18, 2012 10:12 am, edited 2 times in total.
Sorry but, Google translate is my friend 

Re: [Solved] Save content of ClipBoard
Changing the clipboard only as interaction from the user!
You can't restore the clipboard, the clipboard not only hold pictures, text or files!
You can't restore the clipboard, the clipboard not only hold pictures, text or files!
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Re: [Solved] Save content of ClipBoard
Aaaahh !!! Bad news 
Perhaps i can sending text at the cursor of the IDE focused by another way ??

Perhaps i can sending text at the cursor of the IDE focused by another way ??
Sorry but, Google translate is my friend 

Re: [Solved] Save content of ClipBoard
What triggers the action (of sending the snippit)?
How do you know the content you're sending?
cheers
How do you know the content you're sending?
cheers
Re: [Solved] Save content of ClipBoard
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?????
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?????
Sorry but, Google translate is my friend 

Re: [Solved] Save content of ClipBoard
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
[Edit 20/09/21] See bellow a more recent version of the proposed code.
Last edited by Zapman on Fri Sep 20, 2024 4:58 pm, edited 1 time in total.
Re: [Solved] Save content of ClipBoard
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 ?
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 ?
-
- Enthusiast
- Posts: 115
- Joined: Wed Jun 02, 2004 10:17 pm
- Location: New Caledonia (South Pacific)
- Contact:
Re: [Solved] Save content of ClipBoard
Hi, DrGolf,
I revised the procedures to make them more robust:
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()
Last edited by zapman* on Wed Sep 18, 2024 3:39 pm, edited 2 times in total.
Don't try - DO it !