mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-25 01:26:51 +00:00
PDFViewWin:
- start Acrobat with focus and maximized - updated code documentation git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@17192 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
483b78d016
commit
ee654766c3
@ -13,48 +13,23 @@ program PDFViewWin7;
|
|||||||
while the unrenamed version can be modified. When the modified version should
|
while the unrenamed version can be modified. When the modified version should
|
||||||
be displayed, the eventually opened renamed version is closed in Acrobat and
|
be displayed, the eventually opened renamed version is closed in Acrobat and
|
||||||
the modified version is copied, renamed and opened in Acrobat.
|
the modified version is copied, renamed and opened in Acrobat.
|
||||||
To open/close files in Acrobat, the programs "pdfopen" and "pdfclose",
|
To open/close files in Acrobat, OLE-Obcects are used because the latest
|
||||||
written by Fabrice Popineau, is used.}
|
manual "Developing Applications Using Interapplication Communication" from
|
||||||
|
Adobe Acrobat SDK Version 8 states:
|
||||||
|
"Although DDE is supported, you should use OLE automation instead of DDE
|
||||||
|
whenever possible because DDE is not a COM technology."}
|
||||||
|
|
||||||
{$APPTYPE CONSOLE}
|
{$APPTYPE CONSOLE}
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Windows,SysUtils,ShellApi,Forms;
|
Windows,SysUtils,ShellApi,Forms,ComObj,Variants;
|
||||||
|
|
||||||
var Input,InputNew : string;
|
var Input,InputNew : string;
|
||||||
FileTest : boolean;
|
FileTest : boolean;
|
||||||
|
App, AVDoc : Variant;
|
||||||
|
CoInitFlags : Integer = -1;
|
||||||
function ExecWait(const CommandLine: string;
|
VarTest : IDispatch;
|
||||||
const Visible: boolean = false;
|
test : PVariant;
|
||||||
const MaxSeconds: integer = 60): boolean;
|
|
||||||
//Executes programs and waits until they are terminated, taken from
|
|
||||||
//http://www.delphipages.com/tips/thread.cfm?ID=259
|
|
||||||
var
|
|
||||||
SI: TStartupInfo;
|
|
||||||
PI: TProcessInformation;
|
|
||||||
ExitCode: DWORD;
|
|
||||||
begin
|
|
||||||
result := false;
|
|
||||||
GetStartupInfo(SI);
|
|
||||||
if not Visible then
|
|
||||||
begin
|
|
||||||
SI.dwFlags := STARTF_USESHOWWINDOW;
|
|
||||||
SI.wShowWindow := SW_HIDE;
|
|
||||||
end;
|
|
||||||
if CreateProcess(nil, pchar(CommandLine), nil, nil,
|
|
||||||
False, 0, nil, nil, SI, PI) then
|
|
||||||
begin
|
|
||||||
case WaitForSingleObject(PI.hProcess, MaxSeconds * 1000) of
|
|
||||||
WAIT_OBJECT_0: GetExitCodeProcess(PI.hProcess, ExitCode);
|
|
||||||
WAIT_ABANDONED: TerminateProcess(PI.hProcess, ExitCode);
|
|
||||||
WAIT_TIMEOUT: TerminateProcess(PI.hProcess, ExitCode);
|
|
||||||
end;
|
|
||||||
result := ExitCode = 0;
|
|
||||||
CloseHandle(PI.hProcess);
|
|
||||||
CloseHandle(PI.hThread);
|
|
||||||
end;
|
|
||||||
end; //end function
|
|
||||||
|
|
||||||
|
|
||||||
function RenameFile(const OldName, NewName: string): boolean;
|
function RenameFile(const OldName, NewName: string): boolean;
|
||||||
@ -73,8 +48,9 @@ begin
|
|||||||
end; //end function
|
end; //end function
|
||||||
|
|
||||||
|
|
||||||
begin //begin program
|
begin //begin program
|
||||||
|
|
||||||
|
Application.Initialize;
|
||||||
//Read given filename
|
//Read given filename
|
||||||
Input:= ParamStr(1);
|
Input:= ParamStr(1);
|
||||||
//InputNew = original filename with ending "-preview" (e.g. test-preview.pdf)
|
//InputNew = original filename with ending "-preview" (e.g. test-preview.pdf)
|
||||||
@ -82,17 +58,33 @@ begin //begin program
|
|||||||
InputNew:= InputNew+'-preview.pdf';
|
InputNew:= InputNew+'-preview.pdf';
|
||||||
//check if renamed file exists
|
//check if renamed file exists
|
||||||
FileTest:= FileExists(InputNew);
|
FileTest:= FileExists(InputNew);
|
||||||
|
//Create OLE-object for the program Acrobat or Adobe Viewer
|
||||||
|
App:=CreateOleObject('AcroExch.App');
|
||||||
|
//test if given file already exists
|
||||||
if FileTest = true then
|
if FileTest = true then
|
||||||
begin
|
begin
|
||||||
//close old file
|
//close old file
|
||||||
ExecWait('pdfclose --file "'+InputNew+'"');
|
AVDoc:=App.GetActiveDoc; //handle of the active document
|
||||||
|
VarTest:=AVDoc;
|
||||||
|
test:= PVariant(VarTest);
|
||||||
|
if test <> PVariant(0) then //when handle is existing
|
||||||
|
begin
|
||||||
|
try
|
||||||
|
AVDoc.Close(true);
|
||||||
|
except
|
||||||
|
Application.Terminate;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
//delete old file
|
//delete old file
|
||||||
DeleteFile(InputNew);
|
DeleteFile(InputNew);
|
||||||
end;
|
end; //end if FileTest
|
||||||
//rename file
|
//rename file
|
||||||
RenameFile(Input,InputNew);
|
RenameFile(Input,InputNew);
|
||||||
//open renamed file
|
//open renamed file in Acobat or Adobe Viewer
|
||||||
ExecWait('pdfopen --file "'+InputNew+'"');
|
App.Show; //show window
|
||||||
|
App.Restore(true); //restore window size to make window active
|
||||||
|
App.Maximize(true); //maximize window
|
||||||
|
AVDoc:=CreateOleObject('AcroExch.AVDoc'); //create OLE object for file
|
||||||
|
AVDoc.Open(''+InputNew+'',''); //open file
|
||||||
|
|
||||||
|
end. //end program
|
||||||
end. //end program
|
|
||||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user