[Solved] Save content of ClipBoard

Just starting out? Need help? Post your questions and find answers here.
TO7
User
User
Posts: 29
Joined: Wed Dec 03, 2008 9:06 am

[Solved] Save content of ClipBoard

Post 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
Last edited by TO7 on Wed Oct 17, 2012 5:53 pm, edited 1 time in total.
Sorry but, Google translate is my friend :-(
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Re: Save content of ClipBoard

Post 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..
TO7
User
User
Posts: 29
Joined: Wed Dec 03, 2008 9:06 am

Re: Save content of ClipBoard

Post by TO7 »

I know the crossplatform command :wink:

Code: Select all

a$ = GetClipboardText()
SetClipboardText("Hello")
SetClipboardText(a$)
Excuse me, i missing to say all contents :oops:
The problem is if the ClipBoard have other file (xls, exe, etc ..)
Sorry but, Google translate is my friend :-(
User avatar
doctorized
Addict
Addict
Posts: 882
Joined: Fri Mar 27, 2009 9:41 am
Location: Athens, Greece

Re: Save content of ClipBoard

Post by doctorized »

TO7
User
User
Posts: 29
Joined: Wed Dec 03, 2008 9:06 am

Re: Save content of ClipBoard

Post by TO7 »

Thanks for the link
Sorry but, Google translate is my friend :-(
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Re: [Solved] Save content of ClipBoard

Post 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
TO7
User
User
Posts: 29
Joined: Wed Dec 03, 2008 9:06 am

Re: [Solved] Save content of ClipBoard

Post 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)
Last edited by TO7 on Thu Oct 18, 2012 10:12 am, edited 2 times in total.
Sorry but, Google translate is my friend :-(
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: [Solved] Save content of ClipBoard

Post 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!
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.
Image
TO7
User
User
Posts: 29
Joined: Wed Dec 03, 2008 9:06 am

Re: [Solved] Save content of ClipBoard

Post by TO7 »

Aaaahh !!! Bad news :(
Perhaps i can sending text at the cursor of the IDE focused by another way ??
Sorry but, Google translate is my friend :-(
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Re: [Solved] Save content of ClipBoard

Post by rsts »

What triggers the action (of sending the snippit)?

How do you know the content you're sending?

cheers
TO7
User
User
Posts: 29
Joined: Wed Dec 03, 2008 9:06 am

Re: [Solved] Save content of ClipBoard

Post 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?????
Sorry but, Google translate is my friend :-(
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: [Solved] Save content of ClipBoard

Post 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?
User avatar
Zapman
Enthusiast
Enthusiast
Posts: 205
Joined: Tue Jan 07, 2020 7:27 pm

Re: [Solved] Save content of ClipBoard

Post by Zapman »

[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.
drgolf
Enthusiast
Enthusiast
Posts: 106
Joined: Tue Mar 03, 2009 3:40 pm
Location: france

Re: [Solved] Save content of ClipBoard

Post 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 ?
zapman*
Enthusiast
Enthusiast
Posts: 115
Joined: Wed Jun 02, 2004 10:17 pm
Location: New Caledonia (South Pacific)
Contact:

Re: [Solved] Save content of ClipBoard

Post 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()
Last edited by zapman* on Wed Sep 18, 2024 3:39 pm, edited 2 times in total.
Don't try - DO it !
Post Reply