From: remixer
Subject: Clipboard Access on Windows
Date: 
Message-ID: <1158623987.716058.129990@i42g2000cwa.googlegroups.com>
A part of this question is about Lisp/Lisp tools, but other parts of it
are not. This is a project that has been brewing for some time, and I
would love to hack it in Lisp, but want to see the lay of the land
before I pick my tools.

I want to build an application that continuously record information
about everything that is sent to the clipboard. For the sake of
concreteness, imagine a Windows PC, and imagine that I run applications
like Firefox, Word, Outlook/Thunderbird, Notepad, Allegro CL IDE. Also
imagine that whenever I select some text/images/etc in any of the apps
and issue a double-right-click, I want my application to grab 1) the
text/image/etc, 2) the datetime, and 3) a reference to the document
(URL for a website, path for a local file, sender/date/subject for
email, etc). The goal is to make my personal assistant that remembers
things that I care about.

Are there parts of this application that will be very hard or
impossible to do in Lisp? The other choice will be to build
application-specific tools like a Firefox extension, or use .NET. I
would rather use Lisp, but recommendations about stuff that I could
reuse and things to know before I get started on this will be great.

Thank you.

From: =?iso-8859-1?B?QXNiavhybiBCavhybnN0YWQ=?=
Subject: Re: Clipboard Access on Windows
Date: 
Message-ID: <1158632832.635489.203390@e3g2000cwe.googlegroups.com>
remixer wrote:

> Are there parts of this application that will be very hard or
> impossible to do in Lisp? The other choice will be to build
> application-specific tools like a Firefox extension, or use .NET. I
> would rather use Lisp, but recommendations about stuff that I could
> reuse and things to know before I get started on this will be great.

Maybe RDNZL is what you need? It's a ibrary for common lisp
interaction with .NET

http://weitz.de/rdnzl/

-- 
 -asbjxrn
From: remixer
Subject: Re: Clipboard Access on Windows
Date: 
Message-ID: <1158640809.552379.170260@i3g2000cwc.googlegroups.com>
Asbjørn Bjørnstad wrote:
> remixer wrote:
>
> > Are there parts of this application that will be very hard or
> > impossible to do in Lisp? The other choice will be to build
> > application-specific tools like a Firefox extension, or use .NET. I
> > would rather use Lisp, but recommendations about stuff that I could
> > reuse and things to know before I get started on this will be great.
>
> Maybe RDNZL is what you need? It's a ibrary for common lisp
> interaction with .NET
>
> http://weitz.de/rdnzl/

Thanks. I looked at RDNZL and was also thinking about using Corman Lisp
for its Windows support. I was wondering if anyone had more experience
building anything like this which possibly interacts with different
applications like Word, Email client, etc. Or if there are any examples
along those lines. 

> -- 
>  -asbjxrn
From: ·······@gmail.com
Subject: Re: Clipboard Access on Windows
Date: 
Message-ID: <1158797531.511211.269120@e3g2000cwe.googlegroups.com>
remixer wrote:
> Asbjørn Bjørnstad wrote:
> > remixer wrote:
> >
> > > Are there parts of this application that will be very hard or
> > > impossible to do in Lisp? The other choice will be to build
> > > application-specific tools like a Firefox extension, or use .NET. I
> > > would rather use Lisp, but recommendations about stuff that I could
> > > reuse and things to know before I get started on this will be great.
> >
> > Maybe RDNZL is what you need? It's a ibrary for common lisp
> > interaction with .NET
> >
> > http://weitz.de/rdnzl/
>
> Thanks. I looked at RDNZL and was also thinking about using Corman Lisp
> for its Windows support. I was wondering if anyone had more experience
> building anything like this which possibly interacts with different
> applications like Word, Email client, etc. Or if there are any examples
> along those lines.
>
> > --
> >  -asbjxrn

If your Lisp has a good FFI, you can just load the user32.dll et al and
call the Windows API directly. I've done this before with ECL and it
wasn't too bad (using macros to cover over the rough edges helped a
lot). Here's a reference to getting start with the clipboard functions.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wceui40/html/cerefopenclipboard.asp

As for interacting with Word or Email, you'll probably have to stick to
COM, which is much harder to do without C++ due to the requirement of
precise binary contracts. In general, if you don't have much experience
working with Win32 I'd recommend trying it in C++ before Lisp. Not that
Lisp is lacking here, but trying to learn FFI and Win32 at the same
time would probably make any mortal want to tear their own face off.

Asking a Microsoft specific group for help might also help when the
going gets tough. Here's a good one, for example:
http://groups.google.com/group/comp.os.ms-windows.programmer.win32
From: remixer
Subject: Re: Clipboard Access on Windows
Date: 
Message-ID: <1158860155.018972.226050@d34g2000cwd.googlegroups.com>
·······@gmail.com wrote:
> remixer wrote:
> > Asbjørn Bjørnstad wrote:
> > > remixer wrote:
> > >
> > > > Are there parts of this application that will be very hard or
> > > > impossible to do in Lisp? The other choice will be to build
> > > > application-specific tools like a Firefox extension, or use .NET. I
> > > > would rather use Lisp, but recommendations about stuff that I could
> > > > reuse and things to know before I get started on this will be great.
> > >
> > > Maybe RDNZL is what you need? It's a ibrary for common lisp
> > > interaction with .NET
> > >
> > > http://weitz.de/rdnzl/
> >
> > Thanks. I looked at RDNZL and was also thinking about using Corman Lisp
> > for its Windows support. I was wondering if anyone had more experience
> > building anything like this which possibly interacts with different
> > applications like Word, Email client, etc. Or if there are any examples
> > along those lines.
> >
> > > --
> > >  -asbjxrn
>
> If your Lisp has a good FFI, you can just load the user32.dll et al and
> call the Windows API directly. I've done this before with ECL and it
> wasn't too bad (using macros to cover over the rough edges helped a
> lot). Here's a reference to getting start with the clipboard functions.
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wceui40/html/cerefopenclipboard.asp


Thanks a lot. This is exactly what I want in the first version -- just
grab all clipboards. Can you elaborate on "load the user32.dll et al
and call the Windows API directly"? Are there any example code
fragments for doing this available? Also, which Lisps beside ECL can do
this?

> As for interacting with Word or Email, you'll probably have to stick to
> COM, which is much harder to do without C++ due to the requirement of
> precise binary contracts. In general, if you don't have much experience
> working with Win32 I'd recommend trying it in C++ before Lisp. Not that
> Lisp is lacking here, but trying to learn FFI and Win32 at the same
> time would probably make any mortal want to tear their own face off.

Yeah maybe I will steer clear of this until I get the basic
infrastructure in place.

> Asking a Microsoft specific group for help might also help when the
> going gets tough. Here's a good one, for example:
> http://groups.google.com/group/comp.os.ms-windows.programmer.win32
From: Ken Tilton
Subject: Re: Clipboard Access on Windows
Date: 
Message-ID: <PwAQg.17$e05.16@newsfe09.lga>
remixer wrote:
> ·······@gmail.com wrote:
> 
>>remixer wrote:
>>
>>>Asbj�rn Bj�rnstad wrote:
>>>
>>>>remixer wrote:
>>>>
>>>>
>>>>>Are there parts of this application that will be very hard or
>>>>>impossible to do in Lisp? The other choice will be to build
>>>>>application-specific tools like a Firefox extension, or use .NET. I
>>>>>would rather use Lisp, but recommendations about stuff that I could
>>>>>reuse and things to know before I get started on this will be great.
>>>>
>>>>Maybe RDNZL is what you need? It's a ibrary for common lisp
>>>>interaction with .NET
>>>>
>>>>http://weitz.de/rdnzl/
>>>
>>>Thanks. I looked at RDNZL and was also thinking about using Corman Lisp
>>>for its Windows support. I was wondering if anyone had more experience
>>>building anything like this which possibly interacts with different
>>>applications like Word, Email client, etc. Or if there are any examples
>>>along those lines.
>>>
>>>
>>>>--
>>>> -asbjxrn
>>
>>If your Lisp has a good FFI, you can just load the user32.dll et al and
>>call the Windows API directly. I've done this before with ECL and it
>>wasn't too bad (using macros to cover over the rough edges helped a
>>lot). Here's a reference to getting start with the clipboard functions.
>>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wceui40/html/cerefopenclipboard.asp
> 
> 
> 
> Thanks a lot. This is exactly what I want in the first version -- just
> grab all clipboards. Can you elaborate on "load the user32.dll et al
> and call the Windows API directly"? Are there any example code
> fragments for doing this available?

Since you are considering Corman CL, the good news is that it has a 
crapload of examples and predefined bindings to the win32 API.

> Also, which Lisps beside ECL can do
> this?

Check it out: http://common-lisp.net/project/cffi/

But CormanCL has loads of stuff built-in, and one of its users has a web 
page leading to loads  more.

kt

-- 
Cells: http://common-lisp.net/project/cells/

"I'll say I'm losing my grip, and it feels terrific."
    -- Smiling husband to scowling wife, New Yorker cartoon
From: remixer
Subject: Re: Clipboard Access on Windows
Date: 
Message-ID: <1158864339.217285.207580@i42g2000cwa.googlegroups.com>
Ken Tilton wrote:
> remixer wrote:
> > ·······@gmail.com wrote:
> >
> >>remixer wrote:
> >>
> >>>Asbjørn Bjørnstad wrote:
> >>>
> >>>>remixer wrote:
> >>>>
> >>>>
> >>>>>Are there parts of this application that will be very hard or
> >>>>>impossible to do in Lisp? The other choice will be to build
> >>>>>application-specific tools like a Firefox extension, or use .NET. I
> >>>>>would rather use Lisp, but recommendations about stuff that I could
> >>>>>reuse and things to know before I get started on this will be great.
> >>>>
> >>>>Maybe RDNZL is what you need? It's a ibrary for common lisp
> >>>>interaction with .NET
> >>>>
> >>>>http://weitz.de/rdnzl/
> >>>
> >>>Thanks. I looked at RDNZL and was also thinking about using Corman Lisp
> >>>for its Windows support. I was wondering if anyone had more experience
> >>>building anything like this which possibly interacts with different
> >>>applications like Word, Email client, etc. Or if there are any examples
> >>>along those lines.
> >>>
> >>>
> >>>>--
> >>>> -asbjxrn
> >>
> >>If your Lisp has a good FFI, you can just load the user32.dll et al and
> >>call the Windows API directly. I've done this before with ECL and it
> >>wasn't too bad (using macros to cover over the rough edges helped a
> >>lot). Here's a reference to getting start with the clipboard functions.
> >>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wceui40/html/cerefopenclipboard.asp
> >
> >
> >
> > Thanks a lot. This is exactly what I want in the first version -- just
> > grab all clipboards. Can you elaborate on "load the user32.dll et al
> > and call the Windows API directly"? Are there any example code
> > fragments for doing this available?
>
> Since you are considering Corman CL, the good news is that it has a
> crapload of examples and predefined bindings to the win32 API.
>
> > Also, which Lisps beside ECL can do
> > this?
>
> Check it out: http://common-lisp.net/project/cffi/
>
> But CormanCL has loads of stuff built-in, and one of its users has a web
> page leading to loads  more.

Thanks. I think I will go with Corman -- can you provide me the link to
this website you mentioned here?

> kt
>
> --
> Cells: http://common-lisp.net/project/cells/
>
> "I'll say I'm losing my grip, and it feels terrific."
>     -- Smiling husband to scowling wife, New Yorker cartoon
From: Ken Tilton
Subject: Re: Clipboard Access on Windows
Date: 
Message-ID: <LFBQg.14$p53.0@newsfe11.lga>
remixer wrote:
> Ken Tilton wrote:
> 
>>remixer wrote:
>>
>>>·······@gmail.com wrote:
>>>
>>>
>>>>remixer wrote:
>>>>
>>>>
>>>>>Asbj�rn Bj�rnstad wrote:
>>>>>
>>>>>
>>>>>>remixer wrote:
>>>>>>
>>>>>>
>>>>>>
>>>>>>>Are there parts of this application that will be very hard or
>>>>>>>impossible to do in Lisp? The other choice will be to build
>>>>>>>application-specific tools like a Firefox extension, or use .NET. I
>>>>>>>would rather use Lisp, but recommendations about stuff that I could
>>>>>>>reuse and things to know before I get started on this will be great.
>>>>>>
>>>>>>Maybe RDNZL is what you need? It's a ibrary for common lisp
>>>>>>interaction with .NET
>>>>>>
>>>>>>http://weitz.de/rdnzl/
>>>>>
>>>>>Thanks. I looked at RDNZL and was also thinking about using Corman Lisp
>>>>>for its Windows support. I was wondering if anyone had more experience
>>>>>building anything like this which possibly interacts with different
>>>>>applications like Word, Email client, etc. Or if there are any examples
>>>>>along those lines.
>>>>>
>>>>>
>>>>>
>>>>>>--
>>>>>>-asbjxrn
>>>>
>>>>If your Lisp has a good FFI, you can just load the user32.dll et al and
>>>>call the Windows API directly. I've done this before with ECL and it
>>>>wasn't too bad (using macros to cover over the rough edges helped a
>>>>lot). Here's a reference to getting start with the clipboard functions.
>>>>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wceui40/html/cerefopenclipboard.asp
>>>
>>>
>>>
>>>Thanks a lot. This is exactly what I want in the first version -- just
>>>grab all clipboards. Can you elaborate on "load the user32.dll et al
>>>and call the Windows API directly"? Are there any example code
>>>fragments for doing this available?
>>
>>Since you are considering Corman CL, the good news is that it has a
>>crapload of examples and predefined bindings to the win32 API.
>>
>>
>>>Also, which Lisps beside ECL can do
>>>this?
>>
>>Check it out: http://common-lisp.net/project/cffi/
>>
>>But CormanCL has loads of stuff built-in, and one of its users has a web
>>page leading to loads  more.
> 
> 
> Thanks. I think I will go with Corman -- can you provide me the link to
> this website you mentioned here?

Sorry, I should have mentioned that is featured prominently on the 
Corman site: http://www.double.co.nz/cl/index.htm

kt

ps. the win32 trial lisps also come with win32 bindings and great FFIs, 
tho I would recommend CFFI for portability. Last I heard Corman had 
issues with CFFI. If you know C, mastering FFI should be easy. That in 
turn opens up scads of libraries, obviating the only rap on CL.

k

-- 
Cells: http://common-lisp.net/project/cells/

"I'll say I'm losing my grip, and it feels terrific."
    -- Smiling husband to scowling wife, New Yorker cartoon
From: remixer
Subject: Re: Clipboard Access on Windows
Date: 
Message-ID: <1159067289.694768.139240@d34g2000cwd.googlegroups.com>
Thanks everybody. I am able to read clipboard, based on Chris double's
code very easily. I also stumbled across a clisp implementation on this
newsgroup, which looks even cleaner. I want to be able to grab  the
clipboard *when it changes* (rather than polling it all the time, which
is wasteful)

As I understand a WM_COPY message or WM_DRAWCLIPBOARD notification is
generated when the clipboard changes. How does one make a function that
does something when the clipboard change event occurs? I apologize for
the naivete and would be happy if you pointed me in the direction of
any example code fragment that shows how to respond to a windows event
notification. I would be ecstatic if it was using CLISP. 

Thanks.
From: Jack Unrue
Subject: Re: Clipboard Access on Windows
Date: 
Message-ID: <ja0ch21906nbicp03f8cvhj2v6juq9eplt@4ax.com>
On 23 Sep 2006 20:08:09 -0700, "remixer" <········@gmail.com> wrote:
> 
> As I understand a WM_COPY message or WM_DRAWCLIPBOARD notification is
> generated when the clipboard changes. How does one make a function that
> does something when the clipboard change event occurs? I apologize for
> the naivete and would be happy if you pointed me in the direction of
> any example code fragment that shows how to respond to a windows event
> notification. I would be ecstatic if it was using CLISP. 

WM_COPY is a command message sent to a control when one wants
to copy the current selection within the control to the
clipboard. It's not a notification that your application
processes (unless you're implementing a custom control, of
course). As you mentioned, WM_DRAWCLIPBOARD is the message
you need to process.

Here is an introduction to Win32 programming with CL (including
the processing of messages) written in terms of LispWorks:

  http://cl-cookbook.sourceforge.net/win32.html

Here is sample code written in terms of SBCL:

  http://www.lisphacker.com/files/lisp-winapi.tgz
  http://www.lisphacker.com/files/hello-win32.tgz

My library uses CFFI, and here is a pointer to the source
file where I process messages (note that my code is more
complicated than the previous samples as it attempts to
implement somewhat greater functionality):

  http://common-lisp.net/websvn/filedetails.php?repname=graphic-forms&path=%2Ftrunk%2Fsrc%2Fuitoolkit%2Fwidgets%2Fevent.lisp&rev=0&sc=0

Now that you have some references for general message processing
code, you need to delve into the clipboard API to be able to
handle WM_DRAWCLIPBOARD. The following article, although written
in terms of MFC, covers lots of clipboard topics including the
handling of WM_DRAWCLIPBOARD and you might find the whole thing
apropos to what you are trying to do:

  http://www.chiramattel.com/george/Default.aspx?ptabindex=1&ptabid=5

So the challenge then is to translate that info to the equivalent
Lisp code using whichever FFI you've chosen.

You will need to search around in the Win32 programming newsgroups for
more, as I don't have any Lisp-based sample code for this myself (yet).

-- 
Jack Unrue
http://common-lisp.net/project/graphic-forms
From: Jack Unrue
Subject: Re: Clipboard Access on Windows
Date: 
Message-ID: <d9k5h25039a9rdrouhou6rd0tlfrshcgtk@4ax.com>
On 21 Sep 2006 10:35:55 -0700, "remixer" <········@gmail.com> wrote:
> 
> ·······@gmail.com wrote:
> >
> > If your Lisp has a good FFI, you can just load the user32.dll et al and
> > call the Windows API directly. I've done this before with ECL and it
> > wasn't too bad (using macros to cover over the rough edges helped a
> > lot). Here's a reference to getting start with the clipboard functions.
> > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wceui40/html/cerefopenclipboard.asp
> 
> Thanks a lot. This is exactly what I want in the first version -- just
> grab all clipboards. Can you elaborate on "load the user32.dll et al
> and call the Windows API directly"? Are there any example code
> fragments for doing this available? Also, which Lisps beside ECL can do
> this?

Each FFI has its own specific details, but all the Lisps you will
care about have a mechanism that associates a foreign function (which
is the term for a Lisp FFI binding to an external non-Lisp function;
you may also see the term 'alien function') with the library
providing that function; hence the library will be loaded.

If you're not already tied to ECL, you might consider experimenting
with CLISP, since it has a win32 bindings module that happens to include
the clipboard functions. If you're not interested in CLISP, I suggest
that you at least consider writing your FFI code using CFFI
(http://common-lisp.net/project/cffi).

Also, a terminology note: from your point of view, there is only one
clipboard. Clipboard access is restricted to one window at a time,
hence the HWND argument to OpenClipboard. It may have data in zero
or more formats.

> > As for interacting with Word or Email, you'll probably have to stick to
> > COM, which is much harder to do without C++ due to the requirement of
> > precise binary contracts. In general, if you don't have much experience
> > working with Win32 I'd recommend trying it in C++ before Lisp. Not that
> > Lisp is lacking here, but trying to learn FFI and Win32 at the same
> > time would probably make any mortal want to tear their own face off.
> 
> Yeah maybe I will steer clear of this until I get the basic
> infrastructure in place.

I have some reservations about the scope of what you are trying
to do (consider, for instance, that you will need to register
hook functions in order to process mouse clicks within other
application windows), but I think it's always good to experiment
with ideas :-)

> > Asking a Microsoft specific group for help might also help when the
> > going gets tough. Here's a good one, for example:
> > http://groups.google.com/group/comp.os.ms-windows.programmer.win32

Seconded.

-- 
Jack Unrue
From: Jack Unrue
Subject: Re: Clipboard Access on Windows
Date: 
Message-ID: <0al5h2pjiutgb56uv9lmhan3mhipb2dr6g@4ax.com>
I wrote:
>
> Also, a terminology note: from your point of view, there is only one
> clipboard. Clipboard access is restricted to one window at a time,
> hence the HWND argument to OpenClipboard. It may have data in zero
> or more formats.

You might also try implementing a clipboard viewer:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/dataexchange/clipboard/abouttheclipboard.asp

and see how that fits into your plans.

-- 
Jack Unrue