Page 1 of 1

How to get URL of clipboard text?

Posted: Thu Jun 23, 2011 12:12 pm
by Poloboc
Hello!

I'd like to implement a feature similar to the one in CintaNotes in a project of mine:

Clip text from anywhere. Just select it and press the hotkey!
The text-clipping "magic" works in any application that can copy text to clipboard. CintaNotes automatically saves the text and its source URL, and you don't even have to install a plug-in to integrate it with your web browser!


How do you do this programmatically? (Preferably C#, but I guess I can use PInvoke..)

Thanks.

Edit: did some more digging.. is this it? http://msdn.microsoft.com/en-us/library/aa767917%28VS.85%29.aspx
The source url is always included in the base tag of the clipboard data when you copy a selection from a page in a web browser?

Re: How to get URL of clipboard text?

Posted: Fri Jun 24, 2011 4:23 am
by CintaNotes Developer
The main principle is as following: on a hot key CN emulates pressing
Ctrl+C and then examines clipboard. This gets the note's text into CN.
To fill the Link field, in the CF_HTML clipboard data there's indeed a field
SourceURL that contains the page URL, but unfortunately not all
browsers fill out this field (Opera, I'm looking at you ;) )

This is where "Plan B" kicks in. CN sees that there's no URL, but
the program is the browser. So depending on a browser, it sends a
series of keystrokes to focus the address bar, select everything there
and copy it to clipboard.

APIs used:
OpenClipboard
RegisterClipboardFormat
GetClipboardOwner
GetClipboardData
IsClipboardFormatAvailable
EmptyClipboard
SetClipboardData
CloseClipboard
FindWindowEx
GetForegroundWindow
keybd_event
GetWindowThreadProcessId
AttachThreadInput
GetCurrentThreadId
OpenProcess


These are the main points. Hope this helps!!

Re: How to get URL of clipboard text?

Posted: Sat Jun 25, 2011 11:54 am
by Poloboc
Thanks!

I did check to see if SourceURL exists for Chrome, Firefox and IE. Guess I forgot Opera. But everyone seems to forget Opera these days :)

Re: How to get URL of clipboard text?

Posted: Wed Jun 29, 2011 9:21 am
by Kelden
CTRL+C is evil. I did the same before. Use IUI­Automation­Text­Pattern.

Check this page:

What happens when applications try to copy text by sending Ctrl+C
http://blogs.msdn.com/b/oldnewthing/arc ... 78000.aspx

Re: How to get URL of clipboard text?

Posted: Thu Jun 30, 2011 4:14 am
by CintaNotes Developer
Thanks for the comment, Kelden!
The main question for me here is then, do all the apps support the IUI­Automation­Text­Pattern interface?