Some days ago Driessen posted "Qestion about shellexecute" , regarding closing a aplication which was launched from the FW aplication (Shellexcute , TOleAuto() or CreateObject)
In many cases we want that the use closes this aplication , so FW aplication should be disabled till the user closes the other aplication.
Driessen proposed :
- Code: Select all Expand view
ShellExecute(nil,"Open",DOCUMENT)
SYSWAIT(2)
DO WHILE cRet
cRet := .F.
hFile := FOPEN(DOCUMENT,FO_READWRITE + FO_EXCLUSIVE)
IF FERROR() <> 0
cRet := .T.
ELSE
FCLOSE(hFile)
EXIT
ENDIF
SYSREFRESH()
SYSWAIT(0.5)
ENDDO
BUT , THIS DOESN'T WORK IN A MDI ENVIRONNEMENT !
I have found a good solution , using a dialog to start the other aplication with a timer. :
- Code: Select all Expand view
PROC TechnFich()
*****************
LOCAL oDlg , txt , oBut
LOCAL lOk := .T.
LOCAL cFile := "Test.xls"
Txt := "Excel will be launched with Test.xls . You have to close excel before the aplication will continue. This dialog will close automatically"
DEFINE DIALOG oDlg FROM 10,10 TO 200,400 TITLE "Launching and closing excel" PIXEL
@ 10,10 SAY txt OF oDlg SIZE 180,60 PIXEL
@ 60,80 BUTTON oBut PROMPT "Ok" OF oDlg SIZE 40, 12 ACTION Techn_Fich(oDlg , cFile, oBut , @lOk) PIXEL
DlgDisEnable(.F.)
ACTIVATE DIALOG oDlg CENTERED VALID lOk // ON INIT EVAL(oBut:bAction) , with this the dialog is executed without the user has to click on the ok button
DlgDisEnable(.T.)
RETURN
******************************************************************
PROC Techn_Fich(oDlg , cFile , oBut , lOk)
*************************************
LOCAL oSheed , oWorkBook , n
LOCAL hWnd , cCaption
LOCAL oWin , oTimer
lOk := .F.
oBut:DisAble()
TRY
//oExcel := CreateObject( "Excel.Application" )
oExcel := TOleAuto():New( "Excel.Application" )
oWorkBook := oExcel:WorkBooks:open(cFile)
CATCH
oExcel := nil
END
IF ! IsNil(oExcel)
oSheed := oExcel:Get( "ActiveSheet" )
oExcel:Visible := .T.
oWin := oExcel:Get( "ActiveWindow" )
cCaption := oWin:Caption
define timer oTimer interval 500 of oDlg ;
action (IIF(IsNil(hWnd := FindWnd(cCaption)) , (oTimer:DeActivate() , oDlg:bValid := {||.T.} , oDlg:end() , oExcel := nil ) , )) // WindowTopMost ???
activate timer oTimer
END
RETURN
*****************************************
**************************************************************************************
PROC DlgDisEnable(lMOde)
************************
LOCAL el
LOCAL aWin , aDlg[0]
DEFAULT lMode := .F. // Disable
IF ! lMode
oWnd:oMenu:Disable()
ELSE
oWnd:oMenu:Enable()
END
aWin := GetAllWin()
FOR EACH el IN aWin
IF ValType( el ) == "O" .and. Upper( el:ClassName() ) == "TDIALOG" .AND. ! EMPTY(el:cTitle) // .and. o:cTitle == cNonModalTitle
AADD(aDlg,el)
END
NEXT
FOR EACH el In aDlg
IF lMode
el:enable()
ELSE
el:Disable()
end
NEXT
RETURN
*******************************************************************************
// Uit http://fivetechsoft.com/forums/viewtopi ... dwindow%2A
#define GW_HWNDFIRST 0
#define GW_HWNDLAST 1
#define GW_HWNDNEXT 2
#define GW_HWNDPREV 3
#define GW_OWNER 4
#define GW_CHILD 5
FUNCTION FINDWND( cTitle )
LOCAL hWnd := GETWINDOW( GETDESKTOPWINDOW(), GW_CHILD )
WHILE hWnd != 0
IF UPPER( cTitle ) $ UPPER( GETWINDOWTEXT( hWnd ) )
RETURN hWnd
ENDIF
hWnd = GETWINDOW( hWnd, GW_HWNDNEXT )
ENDDO
RETURN NIL