Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Test for existance of Word temporary file 1

Status
Not open for further replies.

white605

Technical User
Jan 20, 2003
394
US
When i use word automation to create the file
Doe.Jane.40090H.obt.doc from a template file a temporary file is created in the same directory -
~$e.Jane.40090H.obt.doc
Is there an easy way to test for the existance of this temporary file to stop people from opening a second read only version of this same file by clicking my button that creates it? or would it be better to somehow test the task manager application list for an instance of word, reguardless of where it came from and only have one instance of word at a time?
wjwjr
 
I have found that using file("filename",1) will test and return true if this temp file exists. Is there a better approach?
wjwjr
 
Hi White,

I'm afraid it's not a simple as that.

would it be better to somehow test the task manager application list for an instance of word, reguardless of where it came from and only have one instance of word at a time?

First, you don't "test the task manager" to find if an instance of a given application is running. You use certain API calls, such as GetWindow(), to see if the application's window is present (this is true even if the window is invisible).

However, I don't see how that would help with this problem, because all you are doing is testing to see if the same user has Word running. What you need to do is to check to see if any user has opened a particular document.

Also, I don't see how testing for file("filename",1) is going to help. The 1 simply tells the function to ignore hidden and system attributes, which don't apply here. You're right that you can use file() to test for the presence of the temporary file, but that assumes that you can reliably determine the name of the temporary file from the original filename. I'm not sure that changing the first two characters to ~$ is always going to do that.

Finally, keep in mind that the temporary file will still be present if another user crashed out of Word. In that case, if you rely on your File() test, no-one would ever be able to open the file in your application again.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Mike, thanks for poining me in the right direction. I searched for getwindow and found post 1251-895526 and adapted Chris's code to work for ms word
Code:
*!* Check for word running
lnHand = IsRun32([Word])

IF lnHand # 0
    MESSAGEBOX( ;
        [My application has ya alreadcy have this file open in the obits] ;
        + CHR(13) ;
        + CHR(13) ;            
        + [My applications version will be terminated],;
        0 + 64 + 0 ,;
        [Adobe Reader])

    RETURN
   ELSE
   WAIT WINDOW [let program run here]
ENDIF


* FUNCTION: Is_Run32.prg
* AUTHOR: George Tasker
* DATE: January 13, 1998 - 8:26 AM
* PURPOSE: Determines if a Windows
* application is running and returns
* the handle of the window if it is,
* otherwise returns 0. 32 bit version
* for Windows 95/NT 3.51-4
* Modified 5/20/2001 - gt

FUNCTION IsRun32
LPARAMETER pctitle

* Parameter list description
*
* pctitle - The title bar of the Window
*   Note: The title does not have to be
*   the complete title that appears
*
*
* API Declarations
DECLARE INTEGER GetDesktopWindow IN Win32API
DECLARE INTEGER GetWindow IN Win32API ;
    INTEGER hwnd ,;
    INTEGER dflag
DECLARE INTEGER GetWindowText IN Win32API ;
    INTEGER hwnd ,;
    STRING @lptstr ,;
    INTEGER cbmax

LOCAL lnhwnd ,;
    lnnext ,;
    lldone ,;
    lctitle_bar ,;
    lcsearchfor ,;
    lntext_len

lcsearchfor = UPPER(ALLTRIM(pctitle))
lnhwnd = GetDesktopWindow()
lnhwnd = GetWindow(lnhwnd, 5) && Get first child window
lnnext = 2
lldone = .F.
lctitle_bar = []

DO WHILE !lldone
    IF !EMPTY(lnhwnd)
        lctitle_bar = SPACE(200) + CHR(0)
        lntext_len = GetWindowText(lnhwnd, @lctitle_bar, 200)
        lctitle_bar = UPPER(LEFT(lctitle_bar, lntext_len))
        lldone = (lcsearchfor $ lctitle_bar)
        IF !lldone
            lnhwnd = GetWindow(lnhwnd, lnnext)
        ENDIF
    ELSE
        lldone = .T.
    ENDIF
ENDDO

RETURN lnhwnd && If 0, not found()
a star for both of you!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top