Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: HTML from Clipboard in Windows

by Corion (Patriarch)
on Aug 09, 2017 at 15:04 UTC ( [id://1197110]=note: print w/replies, xml ) Need Help??


in reply to HTML from Clipboard in Windows

It doesn't seem to be the case currently.

Win32::Clipboard only supports a fixed set of constants and does not pass other formats to the Win32 API.

See this bug report, made just now.

As a fun exercise, I wrote the following:

#!perl -w use strict; use Win32::API; use Win32::Clipboard; use 5.006; our $registerClipboardFormat = Win32::API::More->new( 'user32', 'RegisterClipboardFormat', 'P', 'I' ); die "$^E" unless $registerClipboardFormat; #int WINAPI GetClipboardFormatName( # _In_ UINT format, # _Out_ LPTSTR lpszFormatName, # _In_ int cchMaxCount #); our $_getClipboardFormatName = Win32::API::More->new( 'user32', 'GetClipboardFormatName', 'IPI', 'I' ); die "$^E" unless $_getClipboardFormatName; sub getClipboardFormatName { my( $format ) = @_; my $buffer = "\0" x 1024; my $addr = unpack 'I', pack 'P', $buffer; #print $addr; warn $format; return "<builtin format>" if $format < 17; # CF_MAX $_getClipboardFormatName->Call( $format, $buffer, length $buffer ) or die $^E; $buffer =~ s/\0+$//; $buffer } our $CF_HTML; sub CF_HTML() { $CF_HTML ||= do { $registerClipboardFormat->Call("HTML Format"); }; } my $cb = Win32::Clipboard->new(); for my $fmt ($cb->EnumFormats()) { print getClipboardFormatName( $fmt ), "\n"; }; warn "Retrieving as " . CF_HTML(); print $cb->GetAs(CF_HTML()); print "\ndone\n";

This code lists the names and also fetches the custom formats. I plan to do this as a patch to Win32::Clipboard, but currently don't have the time, sorry.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1197110]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-20 03:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found