Invoking "Word.Application" wityh ole

Post Reply
Frank Demont
Posts: 142
Joined: Sun Oct 09, 2005 10:59 am

Invoking "Word.Application" wityh ole

Post by Frank Demont »

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
Frank Demont
Posts: 142
Joined: Sun Oct 09, 2005 10:59 am

Post by Frank Demont »

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

Code: Select all

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
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Frank,

Try this:

Code: Select all

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
Frank Demont
Posts: 142
Joined: Sun Oct 09, 2005 10:59 am

Post by Frank Demont »

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
Rochinha
Posts: 309
Joined: Sun Jan 08, 2006 10:09 pm
Location: Brasil - Sao Paulo
Contact:

Post by Rochinha »

Frank

See this:

Code: Select all

...
   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
Rochinha
Posts: 309
Joined: Sun Jan 08, 2006 10:09 pm
Location: Brasil - Sao Paulo
Contact:

Post by Rochinha »

Sorry

Its a very little modification

Code: Select all

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. )
Last edited by Rochinha on Mon Feb 19, 2007 3:28 pm, edited 1 time in total.
Ollie
Posts: 233
Joined: Sat Dec 30, 2006 6:10 am

Post by Ollie »

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)
Post Reply