FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour How to make MS WORD on top?
Posts: 1598
Joined: Fri Oct 07, 2005 05:56 PM
How to make MS WORD on top?
Posted: Thu Mar 19, 2020 11:42 AM
Dear All,

I use below code to activate MS Word but it show in background. I need to activate on top of my program.

Code (fw): Select all Collapse
oWord := CreateObject("Word.Application")
oWord:Set("Visible",.t.)
oDoc:Open(cFile)
oWord:Set( "WindowState", 1 )


How do I make on top?

Thanks in advance.
Regards,

Dutch



FWH 2304 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio

FWPPC 10.02 / Harbour for PPC (FTDN)

ADS V.9 / MySql / MariaDB

R&R 12 Infinity / Crystal Report XI R2

(Thailand)
Posts: 1195
Joined: Mon Oct 17, 2005 05:41 AM
Re: How to make MS WORD on top?
Posted: Thu Mar 19, 2020 12:41 PM
Dutch,

You can use
Code (fw): Select all Collapse
Setforegroundwindow(FindWindow("OpusApp",NIL))
Regards,

Marc



FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: How to make MS WORD on top?
Posted: Thu Mar 19, 2020 01:54 PM
Switch from TOP to NORMAL

@ 20, 80 BTNBMP oBtn1 2007 ;
SIZE 30, 30 OF oDlg NOBORDER ;
PROMPT "Top" ;
ACTION ( SetWindowPos( oDlg:hWnd, -1, 0, 0, 0, 0, 3 ),;
WinExec( "Notepad.exe" ) )

close Notepad and reopen with button 2

@ 20, 130 BTNBMP oBtn2 2007 ;
SIZE 30, 30 OF oDlg NOBORDER ;
PROMPT "Normal" ; // Notepad on TOP
ACTION ( SetWindowPos( oDlg:hWnd, -2, 0, 0, 0, 0, 3 ),;
WinExec( "Notepad.exe" ) )

regards
Uwe :-)
Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.
Posts: 1598
Joined: Fri Oct 07, 2005 05:56 PM
Re: How to make MS WORD on top?
Posted: Thu Mar 19, 2020 03:49 PM

Thanks both of you Marc and Uwe. I try and got it work now.

Regards,

Dutch



FWH 2304 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio

FWPPC 10.02 / Harbour for PPC (FTDN)

ADS V.9 / MySql / MariaDB

R&R 12 Infinity / Crystal Report XI R2

(Thailand)
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: How to make MS WORD on top?
Posted: Thu Mar 19, 2020 06:19 PM

Hello Dutch,
would you be so kind to post some code.
Thank you in advance and best regards,
Otto

Posts: 1598
Joined: Fri Oct 07, 2005 05:56 PM
Re: How to make MS WORD on top?
Posted: Fri Mar 20, 2020 01:44 AM
Dear Otto,

I try to use oWord:Mailmerge in my program as customer requirement for make rental contract. I got this code in the forum and modify to support in the future by create temporary file for preparing data (MergeField in Word) and can add or modify in future case.
Otto wrote:Hello Dutch,
would you be so kind to post some code.
Thank you in advance and best regards,
Otto


Code (fw): Select all Collapse
*---------------------------------*
Procedure DocMerge( cForm, cFile )
local oWord, oDoc, cOutFile, cTmpDbf, aTmpDbf, OkToWord , cName
local aDataField, aDatas, n 

CursorWait()

cOutFile := cFile // "d:\fwh1312\samples\testdoc.doc"
cTmpDbf     := MEMVAR->cFoPath+"GSTINFO.DBF" // "d:\fwh1312\samples\guest.dbf"
cFile   := MEMVAR->cFoPath+"LTRFORM\"+cForm // "d:\fwh1312\samples\Rental.doc"

aTmpDbf     := {} 
aDatas  := {} 

DbUseArea(.T.,,"EZMERGE","MRG",.T.)
do while !MRG->(eof())
    aadd( aTmpDbf, {rtrim(upper(MRG->MRG_NAME)), MRG->MRG_TYPE, MRG->MRG_LENGTH, MRG->MRG_DEC} )
    aadd( aDatas , {rtrim(upper(MRG->MRG_NAME)), rtrim(MRG->MRG_DATA)} )
    MRG->(DbSkip())
end
MRG->(DbCloseArea())

if file( cTmpDbf ) 
    ferase( cTmpDbf )
end
if !empty( aTmpDbf )
    
    DbCreate( cTmpDbf, aTmpDbf )
    
    sleep(1000) 
    
    DbUseArea(.T.,,"GSTINFO","GSI",.T.)
    GSI->(DbAppend())
    if GSI->(Rlock())
        for n := 1 to len(aDatas)
             &('GSI->'+aDatas[n][1]) := &(aDatas[n][2])
        next
    end
    GSI->(DbCommit())
    GSI->(DbCloseArea())
    
    oWord := CreateObject("Word.Application")
    oWord:Set("Visible",.f.)
    oDoc:=oWord:Get( "Documents" )
    oWord:Set("DisplayAlerts",0)
    oWord:Set("Visible",.F.)
    oWord:Set( "WindowState", 2 )  // Minimize
    
    oDoc:Open(cFile)
    oWord:ActiveDocument:MailMerge:MainDocumentType := 0 //wdFormLetters=0  // sets the mail merge main document type
    oWord:ActiveDocument:MailMerge:EditMainDocument()
    oWord:ActiveDocument:MailMerge:OpenDataSource(cTmpDbf)  //TmpDbf is the path&file name of temp database
    // oWord:ActiveDocument:MailMerge:Destination( 1 )  // 0=File, 1=Printer, 2=Email, 3=Fax
    oWord:ActiveDocument:MailMerge:Execute( .F. )
    cName:=oWord:Get("ActiveDocument")
    //about to save check to see if possible or if someone else
    //has file open
    
    
    cName:SaveAs(cOutFile)
    IF cName:Saved() == .F.
        MsgStop("Save to Word Fail")
        cOutFile := ''
    ENDIF         
    oWord:Documents:Close(.T.)
    oWord:Quit() 
    
    
    if file(cOutFile)
        ShellExecute(0, 'Open', cOutFile,,4,0)
    end
    
end
CursorArrow()
return
Regards,

Dutch



FWH 2304 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio

FWPPC 10.02 / Harbour for PPC (FTDN)

ADS V.9 / MySql / MariaDB

R&R 12 Infinity / Crystal Report XI R2

(Thailand)

Continue the discussion