FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Invoking "Word.Application" wityh ole
Posts: 142
Joined: Sun Oct 09, 2005 10:59 AM
Invoking "Word.Application" wityh ole
Posted: Sat Feb 17, 2007 11:40 AM

Hello,

I am trying to make a very simple aplication :

 Open a RTF-file with word.exe
 The user can edit this file and MUST save or end word

First i downloaded tWord.zip from patrick's site . I can compile , but i can not make a working sample as described.

Any example is welcome

Frank

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Invoking "Word.Application" wityh ole
Posted: Sat Feb 17, 2007 12:11 PM
To just open a file use

SHELLEXECUTE( 0, 0, "yourfilename", 0, 0, 1 )


EMG
Posts: 142
Joined: Sun Oct 09, 2005 10:59 AM
Invoking "Word.Application" wityh ole
Posted: Sat Feb 17, 2007 05:24 PM
Enrico,

yes , i know , i use this at the moment.

Only , i have problems , probably because i am working in MDI envirronnement , and it is not clear when word.exe receive focus , it can also be later in the program. Not closing the text editor give also problems.



So , i tryed to use ole , hoping to avoid this problems

function MemoEdit( cText)
LOCAL hWnd
Memowrit("C:\TEMP\efkes.rtf",cText)
Shellexecute(0 ,0  , "C:\TEMP\efkes.rtf" ,0 ,0 , 1)          
hWnd := FINDWND( "EFKES.RTF" )
? "Attention , continue only when the text file is corectly closen" 
DO WHIL .T.
    hWnd := FINDWND( "EFKES.RTF" ) 
    IF !EMPTY( hWnd ) 
        ? " rtf-file not closed  : " + CRLF +  GETWINDOWTEXT( hWnd )
       ? "The program closes it "
       SENDMESSAGE( hWnd, 16 ) 
      //CloseWindow(hWnd) 
    ELSE
        EXIT
    END
END
cText := Memoread("C:\TEMP\efkes.rtf" )


After the shellexecute i had to place a msginfo. Working on XP , this give no problems , but at the client , the msginfo appears before the text editor

Has anyone a better solution ?

Frank
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Invoking "Word.Application" wityh ole
Posted: Sun Feb 18, 2007 10:21 AM
Frank,

Try this:
do while ( hWnd := FINDWND( "EFKES.RTF" ) ) == 0
   SysRefresh()
end
? "Attention , continue only when the text file is corectly closen"
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 142
Joined: Sun Oct 09, 2005 10:59 AM
Invoking "Word.Application" wityh ole
Posted: Mon Feb 19, 2007 09:11 AM

Antonio,

The client asked me to avoid the msginfo , but also when i add your code , this seems not to be possible

Now , i see very shortly the meginfo , and then is word activated.

Without the msginfo , i can return to the program without closing word , this gives problems in the next time the shellexecute is activated.
Any idea ?

Frank

Posts: 310
Joined: Sun Jan 08, 2006 10:09 PM
Invoking "Word.Application" wityh ole
Posted: Mon Feb 19, 2007 02:51 PM
Frank

See this:

...
   OLEWORD97(oWndMain,"C:\TEMP\efkes.rtf")
...
FUNCTION OLEWORD97(oOLEWnd,cFName)
   LOCAL oWnd, cWndName := cFileName(cFName) + " - Microsoft Word"
   DEFINE WINDOW oWnd TITLE "FiveWin OLE Support" FROM 0, 0 TO 600, 800 PIXEL
          oWord:=TOleAuto():New( "Word.Application" )
          oWord:Documents:Open( cFName )
          oWord:Visible     := .t.
          oWord:WindowState := 1
          //oWord:PrintOut() // You need print?
          oWord:End()
   ACTIVATE WINDOW oWnd ON INIT (WinExec(cWndName), WinCapsule(oWnd,cWndName)) 
            //VALID ( oWord:End(), .t. )
   RETURN
   
Function WinCapsule(oWin,cWName)
   local lCaptured, hIE
   hIE := FindWindow(0,cWName)
   lCaptured := ( hIE > 0 )
   IF lCaptured
      SetParent(hIE, oWin:hWnd)
      SysRefresh()
   ELSE
      MsgRun('OLE not activated.')
   ENDIF 
   return nil
Posts: 310
Joined: Sun Jan 08, 2006 10:09 PM
Invoking "Word.Application" wityh ole
Posted: Mon Feb 19, 2007 03:25 PM
Sorry

Its a very little modification

FUNCTION OLEWORD97(oOLEWnd,cFName) 
   LOCAL oWnd, oWord, cWndName := cFileName(cFName) + " - Microsoft Word" 
   DEFINE WINDOW oWnd TITLE "FiveWin ActiveX Support" FROM 0, 0 TO 600, 800 PIXEL 
          oWord:=TOleAuto():New( "Word.Application" ) 
          oWord:Documents:Open( cFName ) 
          oWord:Visible     := .t. 
          oWord:WindowState := 1 
          //oWord:PrintOut() 
          //oWord:End() 
   ACTIVATE WINDOW oWnd ON INIT (WinExec(cWndName), WinCapsule(oWnd,cWndName)) ; 
            VALID ( oWord:Quit(), oWord:End(), .t. )
Posts: 233
Joined: Sat Dec 30, 2006 06:10 AM
Invoking "Word.Application" wityh ole
Posted: Tue Jul 10, 2007 01:21 PM

Is this better than using TWORD?

http://fivetechsoft.com/forums/viewtopi ... ight=tword

What do I need to INCLUDE to try the code you have included here?

Many thanks

Ollie.



Using:

xHarbour Compiler build 1.2.1 (SimpLex) (Rev. 6406)

Borland C++ 5.5.1

FWH 9.04 (2009 Apr)

Continue the discussion