Invoking "Word.Application" wityh ole

Invoking "Word.Application" wityh ole

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

Re: Invoking "Word.Application" wityh ole

Postby Enrico Maria Giordano » Sat Feb 17, 2007 12:11 pm

To just open a file use

Code: Select all  Expand view
SHELLEXECUTE( 0, 0, "yourfilename", 0, 0, 1 )


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby Frank Demont » Sat Feb 17, 2007 5: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

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

Postby Antonio Linares » Sun Feb 18, 2007 10:21 am

Frank,

Try this:
Code: Select all  Expand view
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
User avatar
Antonio Linares
Site Admin
 
Posts: 42078
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Frank Demont » Mon Feb 19, 2007 9: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
Frank Demont
 
Posts: 142
Joined: Sun Oct 09, 2005 10:59 am

Postby Rochinha » Mon Feb 19, 2007 2:51 pm

Frank

See this:

Code: Select all  Expand view
...
   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: 310
Joined: Sun Jan 08, 2006 10:09 pm
Location: Brasil - Sao Paulo

Postby Rochinha » Mon Feb 19, 2007 3:25 pm

Sorry

Its a very little modification

Code: Select all  Expand view
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.
Rochinha
 
Posts: 310
Joined: Sun Jan 08, 2006 10:09 pm
Location: Brasil - Sao Paulo

Postby Ollie » Tue Jul 10, 2007 1: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)
Ollie
 
Posts: 233
Joined: Sat Dec 30, 2006 6:10 am


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 23 guests