Know if there's Rich Text in Clipboard

Just starting out? Need help? Post your questions and find answers here.
User avatar
VB6_to_PBx
Enthusiast
Enthusiast
Posts: 627
Joined: Mon May 09, 2011 9:36 am

Know if there's Rich Text in Clipboard

Post by VB6_to_PBx »

is there anyway to tell if there is Rich Text pasted or copied to the Clipboard ???

or anyway to tell if whats in the Clipboard is RichText or plain Text or even a Picture ???

i'm using PB5.31 (86) Windows 7

the only Link i found about this was :
http://forums.purebasic.com/english/vie ... hp?p=87021
but its not able to distinguish between Rich Text and plain Text in the Clipboard
 
PureBasic .... making tiny electrons do what you want !

"With every mistake we must surely be learning" - George Harrison
juror
Enthusiast
Enthusiast
Posts: 233
Joined: Mon Jul 09, 2007 4:47 pm
Location: Courthouse

Re: Know if there's Rich Text in Clipboard

Post by juror »

windows

cf_RTF=RegisterClipboardFormat_("Rich Text Format")

If IsClipboardFormatAvailable_(CF_RTF)

Image = no need to register = known format
If IsClipboardFormatAvailable_(#CF_BITMAP) ;is an image present?

Text=Known format
If IsClipboardFormatAvailable_(#CF_TEXT)

Standard (known) formats
https://msdn.microsoft.com/en-us/librar ... 2147217396
User avatar
VB6_to_PBx
Enthusiast
Enthusiast
Posts: 627
Joined: Mon May 09, 2011 9:36 am

Re: Know if there's Rich Text in Clipboard

Post by VB6_to_PBx »

juror wrote:windows

cf_RTF=RegisterClipboardFormat_("Rich Text Format")

If IsClipboardFormatAvailable_(CF_RTF)

Image = no need to register = known format
If IsClipboardFormatAvailable_(#CF_BITMAP) ;is an image present?

Text=Known format
If IsClipboardFormatAvailable_(#CF_TEXT)

Standard (known) formats
https://msdn.microsoft.com/en-us/librar ... 2147217396

thanks juror ,
works great !!! ( PB5.31 )
:)

Code: Select all

CF_RTF=RegisterClipboardFormat_("Rich Text Format")
Debug  IsClipboardFormatAvailable_(CF_RTF)
;~~~~~ 1 = yes, there is Rich Text copied into Clipboard
;~~~~~ 0 = no 
 
PureBasic .... making tiny electrons do what you want !

"With every mistake we must surely be learning" - George Harrison
User avatar
VB6_to_PBx
Enthusiast
Enthusiast
Posts: 627
Joined: Mon May 09, 2011 9:36 am

Re: Know if there's Rich Text in Clipboard

Post by VB6_to_PBx »

Code: Select all


CF_RTF = RegisterClipboardFormat_("Rich Text Format")
Debug IsClipboardFormatAvailable_(CF_RTF)
;~~~~~ 1 = yes, there is Rich Text copied into Clipboard
;~~~~~ 0 = no 


CF_HTML=RegisterClipboardFormat_("HTML Format")
Debug IsClipboardFormatAvailable_(CF_HTML)
;~~~~~ 1 = yes, there is HTML Text copied into Clipboard
;~~~~~ 0 = no 


; CF_Bitmap = 2
; Debug IsClipboardFormatAvailable_(CF_Bitmap)
Debug IsClipboardFormatAvailable_(#CF_BITMAP)
;~~~~~ 1 = yes, there is a Picture copied into Clipboard
;~~~~~ 0 = no 


Debug IsClipboardFormatAvailable_(#CF_TEXT)
;~~~~~ 1 = yes, there is plain Text copied into Clipboard
;~~~~~ 0 = no 

 
PureBasic .... making tiny electrons do what you want !

"With every mistake we must surely be learning" - George Harrison
juror
Enthusiast
Enthusiast
Posts: 233
Joined: Mon Jul 09, 2007 4:47 pm
Location: Courthouse

Re: Know if there's Rich Text in Clipboard

Post by juror »

Requires EnumClipboardFormats_(j), but will give you an idea.

Code: Select all

Procedure.s GetClipboardFormatName(format)
  Structure CFNAME
    value.l
    name.s
  EndStructure
  Protected fmts=17, fmt$
  Dim CFNames.CFNAME(fmts)
  CFNames(0)\value = 0
  CFNames(0)\name = "Unused"
  CFNames(1)\value = 1
  CFNames(1)\name = "CF_TEXT"
  CFNames(2)\value = 2
  CFNames(2)\name = "CF_BITMAP"
  CFNames(3)\value = 3
  CFNames(3)\name = "CF_METAFILEPICT"
  CFNames(4)\value = 4
  CFNames(4)\name = "CF_SYLK"
  CFNames(5)\value = 5
  CFNames(5)\name = "CF_DIF"
  CFNames(6)\value = 6
  CFNames(6)\name = "CF_TIFF"
  CFNames(7)\value = 7
  CFNames(7)\name = "CF_OEMTEXT"
  CFNames(8)\value = 8
  CFNames(8)\name = "CF_DIB"
  CFNames(9)\value = 9
  CFNames(9)\name = "CF_PALETTE"
  CFNames(10)\value = 10
  CFNames(10)\name = "CF_PENDATA"
  CFNames(11)\value = 11
  CFNames(11)\name = "CF_RIFF"
  CFNames(12)\value = 12
  CFNames(12)\name = "CF_WAVE"
  CFNames(13)\value = 13
  CFNames(13)\name = "CF_UNICODETEXT"
  CFNames(14)\value = 14
  CFNames(14)\name = "CF_ENHMETAFILE"
  CFNames(15)\value = 15
  CFNames(15)\name = "CF_GDROP"
  CFNames(16)\value = 16
  CFNames(16)\name = "CF_LOCALE"
  CFNames(17)\value = 17
  CFNames(17)\name = "CF_DIBV5"
  ;ReturnValue.s = "NOT FOUND"
  If format=0
    ProcedureReturn""
  EndIf
  
  For i = 1 To fmts
    If format = CFNames(i)\value
     fmt$ = CFNames(i)\name
      Break
    EndIf
  Next
  If fmt$=""
    fmt$=Space(128)
    If GetClipboardFormatName_(format,@fmt$,64)
    Else
      fmt$="Unknown"
    EndIf
  EndIf  ;fmt$=""  
  
  ProcedureReturn fmt$
EndProcedure
User avatar
VB6_to_PBx
Enthusiast
Enthusiast
Posts: 627
Joined: Mon May 09, 2011 9:36 am

Re: Know if there's Rich Text in Clipboard

Post by VB6_to_PBx »

juror ,

many thanks for adding all those other Clipboard Format Names !!!

much appreciated !
 
PureBasic .... making tiny electrons do what you want !

"With every mistake we must surely be learning" - George Harrison
Post Reply