Hi all,

Is there an easy way to get the hWnd ( of main app window ) for an
application
launched using CreateOLEObject()?

Our application provides document management services and mail-merge from
organization data, and the aim is to use Word as an editor for the
documents.
I don't want to use an OLE container for this, for various reasons.

One use-case for this is something like:  The user selects the document
record,
then presses 'Edit.'The application extracts a document from the BLOb field
on the database then
launches Word, with the document open. The user edits, then saves the
document
to disk, then closes Word.  ON WORD CLOSING, the document is copied from
disk
into the BLOb field on the database's Documents table.

The reason I want the HWnd is that I don't want my launch() function to
return
until Word closes.  What I plan to do is something like:

// start snippet

if (WordOLEType = wotApplication) then
  olevarWord.Application.Visible := True
else if (WordOLEType = wotBasic) then
  olevarWord.AppShow;

// wait through short pause while Word activates.
while not IsWindowVisible( hwndWord ) do Application.ProcessMessages;
// wait until Word closes
while IsWindowVisible( hwndWord ) do Application.ProcessMessages;

// end snippet

My app throws an EOLESysError every time a modal dialog is opened in Word
while polling using OLE. This means I can't test for EOLESysErrors as a way
of
finding when Word  closes.  Excel and Access both have OLE properties for
hWnd  (hWndAccessApp, xlHWnd) but &%^#$@&* Word hasn't any that I can find.

I don't want to have to use FindWindow() (Not sure if window class name
'OpusApp'
is identical for all versions of Word, besides which there may already be
instances
of Word still 'alive' from elsewhere, also FindWindow seems to return the
handle it
finds first and is effectively random with multiple instances AFAIAA.)  I
also don't
want to have to specify a template for all documents to be used with the
system.

Has anyone had any success with similar things?  Should I be doing this a
different
way?

Cheers,

Cory.


---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz

Reply via email to