Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Windows: Get current text + cursor position from external program?

0 views
Skip to first unread message

Kallepalle

unread,
Jan 16, 2004, 8:32:00 AM1/16/04
to
Hi!

I need to be able to do the following from an external program under
Windows:

1) Determine if the current window is a StarWriter window
2) Get the current text in the document
3) Get the current cursor position
4) Define a range, and change the contents (text) of the range

This ought to be fairly simple, but I have yet to find a usable
tutorial on how to accomplish this using COM, OLE, Windows messages or
other mechanism, which is available to Windows programs.

Can anyone give me a pointer, or supply me with some code to get
started with? Alternatively I am willing to pay for a working
implementation in C++...

Sincerely,
Anders S. Johansen

James Lee

unread,
Jan 16, 2004, 10:35:23 AM1/16/04
to
On Fri, 16 Jan 2004 05:32:00 -0800, Kallepalle wrote:

> I need to be able to do the following from an external program under
> Windows:
>
> 1) Determine if the current window is a StarWriter window
> 2) Get the current text in the document
> 3) Get the current cursor position
> 4) Define a range, and change the contents (text) of the range

> This ought to be fairly simple,

Yes, it's "fairly simple".

> but I have yet to find a usable tutorial
> on how to accomplish this using COM, OLE, Windows messages or other
> mechanism, which is available to Windows programs.

I don't think you can using COM. The equivalent is the UNO interface.


> Can anyone give me a pointer, or supply me with some code to get started
> with?

http://api.openoffice.org/


> Alternatively I am willing to pay for a working implementation in C++...

Well if you are happy with Java...

Kallepalle

unread,
Jan 17, 2004, 5:56:13 AM1/17/04
to
James Lee <sp4...@hotmail.com> wrote in message news:<pan.2004.01.16....@hotmail.com>...

> On Fri, 16 Jan 2004 05:32:00 -0800, Kallepalle wrote:
>
> > I need to be able to do the following from an external program under
> > Windows:
> >
> > 1) Determine if the current window is a StarWriter window
> > 2) Get the current text in the document
> > 3) Get the current cursor position
> > 4) Define a range, and change the contents (text) of the range
>
> > This ought to be fairly simple,
>
> Yes, it's "fairly simple".

I assumed as much ;)

However...

> > Can anyone give me a pointer, or supply me with some code to get started
> > with?
>
> http://api.openoffice.org/

...such things are only simple, once one has the context. Even getting
to the "hello, world" stage in /any/ new system is hard. It has it's
own internal logic, which you have to grok, and tools to set up etc.
etc.

Man, hvad I ever spent much time already staring at that site. And I'm
a graduate student of computer science even! ;) Doesn't help. At least
not much :D

> > Alternatively I am willing to pay for a working implementation in C++...
>
> Well if you are happy with Java...

Sorry, but has to be C++ as I have a working program written in C++,
which already interfaces with a lot of other classes of Windows
programs. It's just not feasible to rewrite it all at this stage.

I suppose that worst case I could use a Java implementation, and then
find some way to translate that into C++ (or some gateway/adaptor or
whatever...), so hold the thought!

A

James Lee

unread,
Jan 19, 2004, 7:06:52 AM1/19/04
to
On Sat, 17 Jan 2004 02:56:13 -0800, Kallepalle wrote:

>> http://api.openoffice.org/
>
[snip]


>
> Man, hvad I ever spent much time already staring at that site. And I'm a
> graduate student of computer science even! ;) Doesn't help. At least not
> much :D

I understand exactly what you mean!


>> Well if you are happy with Java...
>
> Sorry, but has to be C++ as I have a working program written in C++,
> which already interfaces with a lot of other classes of Windows
> programs. It's just not feasible to rewrite it all at this stage.
>
> I suppose that worst case I could use a Java implementation, and then
> find some way to translate that into C++ (or some gateway/adaptor or
> whatever...), so hold the thought!

You don't link with the office libraries anyway, you only talk to a
running program via a network interface. The SDK offers a library of
functions that run on your side of the interface. Unfortunately there are
problems doing this directly, (like how to start the office program. It
can't be done on the program's API because it's not there!)

I have implemented a solution that was self contained. It presented a
general TCP/IP interface to the customer's programs. One of programs I
delivered to demonstrate how to use was written in perl - so you can see
interfacing is simple. The aim was to present a simple and robust
interface to the outside and manage (hide!) all the complexities of
SO/OOo.

I'm not sure if you need an on demand or a batch service. For on demand
you have to carefully manage SO/OOo as the API and core program is not
multi-threaded in the way we need. (It works for typing because you can
only type in one window at a time.)

Although the SO/OOo UNO interface is a network one it is best not
presented to the network because of the threading problem.

Creating the wrapper allows you to put the office part on another machine.

I have (and would prefer to) put my classes within a JSP/Servlet Java
server for a more completely integrated service, ie, if you want to offer
the service via a browser it makes sense to do it in one hit - but you
seem to already have your application.

Kallepalle

unread,
Jan 19, 2004, 4:08:01 PM1/19/04
to
> > Man, hvad I ever spent much time already staring at that site. And I'm a
> > graduate student of computer science even! ;) Doesn't help. At least not
> > much :D
>
> I understand exactly what you mean!

Yah, the dreaded learning cliff ;)

> You don't link with the office libraries anyway, you only talk to a
> running program via a network interface. The SDK offers a library of
> functions that run on your side of the interface. Unfortunately there are
> problems doing this directly, (like how to start the office program. It
> can't be done on the program's API because it's not there!)

Luckily I don't have to start SO/OO! I am quite happy being able to
talk to the active document. You can see a few screenshots of my app
here:
http://www.secondguess.dk/skrivestotte/universel.html

It's a toolbar-type window, which floats next to the client window,
providing support functions for dyslexic computer users.

What I do is poll the system for, whether the current foreground
window has changed. If it has, I check if the new foreground window is
supported by my app - this I need to be able to do for SO/OO - and if
so, I need to be able to perform the functions I mentioned in my
original mail.

Determining that type of app the current window is, is usually done by
a combination of different methods + trial & error ;) You can for
example request the class name of the window, but for classes
extending the common Edit and Rich Edit controls the class name may
have changed, and you will need to perform extra tests.. which are not
guaranteed to work :( Evil, evil Windows world...

...however I'm sure a way to determine if a given window contains an
SO/OO app. I'll find a way for sure.

> I'm not sure if you need an on demand or a batch service. For on demand
> you have to carefully manage SO/OOo as the API and core program is not
> multi-threaded in the way we need. (It works for typing because you can
> only type in one window at a time.)

I'm not really sure if what I need falls in one category or the
other... This could be considered a borderline case for either, and
not knowing the complexities of the SO/OO interface I don't know which
way to call it.

> I have (and would prefer to) put my classes within a JSP/Servlet Java
> server for a more completely integrated service, ie, if you want to offer
> the service via a browser it makes sense to do it in one hit - but you
> seem to already have your application.

I do indeed, but it sounds to me like something could actually be made
to function.

A

James Lee

unread,
Jan 21, 2004, 4:42:58 AM1/21/04
to
On Mon, 19 Jan 2004 13:08:01 -0800, Kallepalle wrote:

> Luckily I don't have to start SO/OO! I am quite happy being able to talk
> to the active document. You can see a few screenshots of my app here:
> http://www.secondguess.dk/skrivestotte/universel.html

So guessing what the words mean... Your application already works with
those MS programs and you'd like it to work with SO/OO too.


>> I'm not sure if you need an on demand or a batch service. For on demand
>> you have to carefully manage SO/OOo as the API and core program is not
>> multi-threaded in the way we need. (It works for typing because you can
>> only type in one window at a time.)
>
> I'm not really sure if what I need falls in one category or the other...
> This could be considered a borderline case for either, and not knowing
> the complexities of the SO/OO interface I don't know which way to call
> it.

It's more like the batch, but simpler. The problem with on-demand is the
asynchronous calls, sadly it's not robust enough. (Because although the
multiple frames look threaded it isn't and it wasn't design to be that
robust - according to the writers. I'm stupid be because if I have
something that looks threaded then I use threads and pass the complexities
to a something else) Batch to me implies queued, hence one-at-a-time.

Having decided this is "simple", do the examples here not help:

http://api.openoffice.org/source/browse/api/odk/examples/cpp/

James Lee

unread,
Aug 6, 2004, 6:00:19 AM8/6/04
to
On Mon, 19 Jan 2004 13:08:01 -0800, Kallepalle wrote:

> Luckily I don't have to start SO/OO! I am quite happy being able to talk
> to the active document. You can see a few screenshots of my app here:
> http://www.secondguess.dk/skrivestotte/universel.html

So guessing what the words mean :-) This already supports the MS programs
and you want to offer the same service to StarOffice/OpenOffice.


>> I'm not sure if you need an on demand or a batch service. For on demand
>> you have to carefully manage SO/OOo as the API and core program is not
>> multi-threaded in the way we need. (It works for typing because you can
>> only type in one window at a time.)
>
> I'm not really sure if what I need falls in one category or the other...
> This could be considered a borderline case for either, and not knowing
> the complexities of the SO/OO interface I don't know which way to call
> it.

More like the batch, but thankfully much more like the API was intended
and therefore much simpler. [The problem with an on demand service (web
server) is the asynchronous multiple requests.]

So having decide this is "simple", do the examples here help? :
http://api.openoffice.org/source/browse/api/odk/examples/cpp/

Another thought, to talk to a running SO/OOo it must be started in a
listening mode. Normally it don't listen on the port, and has to be
started with args like:
"-accept=socket,host=localhost,port=8100;urp;StarOffice.ServiceManager"


0 new messages