Edit
Attach
Printable
topic end
<!-- * Set TOPICTITLE = <nop>CoCreate Modeling code examples: Exchanging text via the Windows clipboard --> <style type="text/css"> pre { background-color:#FFEECC; } </style> ---++ <nop>CoCreate Modeling: Exchanging text via the Windows clipboard We already discussed how Lisp code in <nop>CoCreate Modeling can communicate with other components in various ways: * With Excel via [[MacroHelloExcel][DDE]] (see also the [[FaqDde][DDE FAQ]]) * With external processes by [[MacroAlarmClock][running them from <nop>CoCreate Modeling]] * By [[MacroEnumerateDrives][calling <nop>VBscript code]] (see also [[MacroDefaultPrinter][this example]]) And now it's about time to explore yet another dimension of interprocess communication - using COM objects. A customer recently asked for help - he needed code which exchanges data with other applications via the Windows clipboard. There is no officially supported API for this kind of communication in the Integration Kit. However, that's not really a problem because access of the clipboard is provided as a service by the COM object "InternetExplorer.Application" which is available on pretty much any Windows system. We can use Lisp to ask that COM object to help us with clipboard communication. [[http://www.microsoft.com/technet/scriptcenter/resources/qanda/dec04/hey1215.mspx][This article]] at the Windows Script Center website shows how to use the =InternetExplorer.Application= object from <nop>VBscript; all we need to do is to translate that example into equivalent Lisp code - such as the following. <pre> <font color="#0000ff">;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;</font> <font color="#0000ff">;; Description: Read text from and write text to the clipboard</font> <font color="#0000ff">;; using COM objects</font> <font color="#0000ff">;; Requires .NET API license</font> <font color="#0000ff">;; Author: Claus Brod </font> <font color="#0000ff">;; Language: Lisp</font> <font color="#0000ff">;;</font> <font color="#0000ff">;; (C) Copyright 2007 Claus Brod, all rights reserved</font> <font color="#0000ff">;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;</font> <font color="#6a5acd">(</font><font color="#804040"><b>in-package</b></font> :clausbrod.de<font color="#6a5acd">)</font> <font color="#6a5acd">(</font><font color="#804040"><b>defun</b></font> get-clipboard-object<font color="#6a5acd">()</font> <font color="#6a5acd">(</font><font color="#804040"><b>let</b></font> <font color="#6a5acd">((</font>ie <font color="#6a5acd">(</font>.net:create-object <font color="#ff00ff">"InternetExplorer.Application"</font><font color="#6a5acd">)))</font> <font color="#6a5acd">(</font>.net:invoke ie <font color="#ff00ff">"Navigate"</font> <font color="#ff00ff">"about:blank"</font><font color="#6a5acd">)</font> <font color="#6a5acd">(</font>.net:get-property <font color="#6a5acd">(</font>.net:get-property <font color="#6a5acd">(</font>.net:get-property ie <font color="#ff00ff">"Document"</font><font color="#6a5acd">)</font> <font color="#ff00ff">"Parentwindow"</font><font color="#6a5acd">)</font> <font color="#ff00ff">"ClipboardData"</font><font color="#6a5acd">)))</font> <font color="#6a5acd">(</font><font color="#804040"><b>defun</b></font> text-to-clipboard<font color="#6a5acd">(</font>text<font color="#6a5acd">)</font> <font color="#6a5acd">(</font>.net:invoke <font color="#6a5acd">(</font>get-clipboard-object<font color="#6a5acd">)</font> <font color="#ff00ff">"SetData"</font> <font color="#ff00ff">"Text"</font> text<font color="#6a5acd">))</font> <font color="#6a5acd">(</font><font color="#804040"><b>defun</b></font> text-from-clipboard<font color="#6a5acd">()</font> <font color="#6a5acd">(</font>.net:invoke <font color="#6a5acd">(</font>get-clipboard-object<font color="#6a5acd">)</font> <font color="#ff00ff">"GetData"</font> <font color="#ff00ff">"Text"</font><font color="#6a5acd">))</font> </pre> So how does this code work? First we need to instantiate and connect to =InternetExplorer.Application=; this is the first thing which =(get-clipboard-object)= does. "Instantiation" means that an Internet Explorer process is started in the background (unless an instance of IE is already running). Second, we ask the =InternetExplorer.Application= to open a blank document. This is a prerequisite for the next step. From the document object that we created, we can ask our way through to the =ClipboardData= object (the full object path is =Document.Parentwindow.ClipboardData=). This is the job of the =get-clipboard-object= function. And finally, the =ClipboardData= object has two member functions which are most useful to us: =GetData= and =SetData=. =GetData= can be used to retrieve data from the clipboard, while =SetData= pushes data to the Windows clipboard. Both functions expect us to specify the format of the data that we expect on the clipboard - in our case "Text". Legal warning: You need a license to use the COM/.NET API. Please contact CoCreate support for details. -- Main.ClausBrod - 11 Apr 2007 %COMMENT{type="below" nonotify="on"}%
to top
End of topic
Skip to action links
|
Back to top
Edit
|
Attach image or document
|
Printable version
|
Raw text
|
Refresh
|
More topic actions
Revisions: | r1.5 |
>
|
r1.4
|
>
|
r1.3
|
Total page history
|
Backlinks
You are here:
CoCreateModeling
>
TextFromAndToClipboard
r1.5 - 24 Jul 2009 - 21:30 -
ClausBrod
to top
CoCreateModeling
CoCreate Modeling
FAQ
Introduction
Hardware
Operating system
Memory management
File handling
Installation
Licensing
Graphics
App. knowhow
Lisp
Learning
Programming
Debugging
DDE
Compiler
Customization
Troubleshooting
Links
Code examples
Viewbench
News
Changes
Index
Search
Impressum
Home
Webs
Atari
Blog
Claus
CoCreateModeling
Klassentreffen
Main
Sandbox
Sommelier
TWiki
Xplm
My links
edit
TWiki
Welcome
TWiki Web TWiki Web Home Changes Topics Index Search
TWiki Webs Atari Blog Main
OneSpaceModeling
?
Sandbox TWiki TWiki Webs Atari Blog Main
OneSpaceModeling
?
Sandbox TWiki
Jump:
Copyright © 1999-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki?
Send feedback