Home > Back-end >  Please advice on how to determine a word document close issue
Please advice on how to determine a word document close issue

Time:10-21

Delphi program to open the word document, such as "c: \ aaa. Doc" (independent start word interface, not embedded in my program), when manually close the word document, because I want to triple-a. Doc document for subsequent processing, how could my program is detected or to judge this document has been completely shut down Windows message interception (without the timer),
The younger brother only 160 points, give full marks, please feel free to comment!!!!!!

CodePudding user response:

What is your follow-up action?
If you need an exclusive operation, add a exception statements should be able to achieve a goal
Try
//the processing of you
Except,
//can't perform processing
end;

CodePudding user response:

Follow-up is to save the word document, so no, you said I add exception statements procedures which place

CodePudding user response:

Follow-up is to save the word document to my database

CodePudding user response:

In fact, I want to say to a friend on the second floor is the purpose of exception handling statement to find a place to write

CodePudding user response:

Call IsFileInUse, returns False said the file is not open,

 
The function IsFileInUse (fName: string) : Boolean;
Var
HFileRes: HFILE;
The begin
//http://blog.sina.com.cn/s/blog_4960dbcb0100gofb.html
Result:=false;//the return value is false (that is, the file is not used)
If not FileExists (fName) then the exit;//if the file does not exist the exit
HFileRes:=CreateFile (Pchar (fName), GENERIC_READ or GENERIC_WRITE,
0 {this is the was catnip! }, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
Result:=(HFileRes=INVALID_HANDLE_VALUE);//if CreateFile returns failure, then the Result is true (that is, the file is being used)
If not the Result is then//if the CreateFile function returns success
The CloseHandle (HFileRes);//then close the handle
end;

CodePudding user response:

Don't know what's the news can monitor to the
I can think of is the Timer or thread

CodePudding user response:

Help under the roof, can't figure out how to judge the word close

CodePudding user response:

Fifth floor friend idea is very good, is worth reference, but in a program where IsFileInUse function called, if it's not the timer

CodePudding user response:

refer to the eighth floor italyycm response:
5 floor friend idea is very good, is worth reference, but in a program where IsFileInUse function called, if it's not the timer


You can use the WaitForSingleObject and WaitForMultipleObjects two functions to implement this chain,
Under the reference in the following article "2, waiting for the existing process"
http://share-sy.blogbus.com/logs/96942232.html

CodePudding user response:

references 9 f feiba7288 response:
refer to the eighth floor italyycm response:
Fifth floor friend idea is very good, is worth reference, but in a program where IsFileInUse function called, if it's not the timer

You can use the WaitForSingleObject and WaitForMultipleObjects two functions to implement this chain,
Under the reference in the following article "2, waiting for the existing process"
http://share-sy.blogbus.com/logs/96942232...


Too complicated, I just entry level is limited, which eldest brother can help me to write the program
  • Related