I've made a program in Object Pascal which works ok. I was wondering if the Pascal code below could be done with newLisp. That would for me a more convenient solution for my project, that already uses newlisp.dll (see http://www.mcmusiceditor.com). Here the central part of the Pascal code that does the job (the complete code is at the end of the email). The idea: if there is no default PDF viewer, invoke MCMsumatrapdf.exe only if the loaded file is test2.pdf; otherwise show a message. Of course, if there is a default PDF viewer, then the file will be shown.
Code: Select all
SetCurrentDirectory(pchar(ExtractFilePath(paramstr(0))));
result:=ShellExecute(0, 'open', pchar(paramstr(1)), nil, nil, SW_SHOWNORMAL);
if result = SE_ERR_NOASSOC
then
begin
(* if no duplicates as in case of calling the help file help\test2.ppx, invoke MCMsumatrapdf.exe; in other cases like View PDF show the message box *)
if paramstr(1) = 'help\test2.pdf'
then
begin
cmd:='MCMsumatrapdf.exe ';
cmd:=cmd+'"'+paramstr(1)+'"';
WinExec(pchar(cmd),SW_SHOWNORMAL);
end
else
MessageBox(0,'There is no application associated with a PDF file. ...','No PDF file association!',MB_OK or MB_ICONINFORMATION)
end
except
end;
end.
Regards,
Reinier
Code: Select all
{$H+}
{$R manifest.res}
program pdfview;
uses
{$IFNDEF FPC}
ShellApi,
{$ENDIF}
Windows;
{$IFNDEF FPC}
const
AllowDirectorySeparators : set of char = ['\','/'];
AllowDriveSeparators : set of char = [':'];
{$ENDIF}
var
cmd:string;
result:thandle;
function ExtractFilePath(const FileName: string): string;
var
i : longint;
EndSep : Set of Char;
begin
i := Length(FileName);
EndSep:=AllowDirectorySeparators+AllowDriveSeparators;
while (i > 0) and not (FileName[i] in EndSep) do
Dec(i);
If I>0 then
Result := Copy(FileName, 1, i)
else
Result:='';
end;
begin
try
SetCurrentDirectory(pchar(ExtractFilePath(paramstr(0))));
result:=ShellExecute(0, 'open', pchar(paramstr(1)), nil, nil, SW_SHOWNORMAL);
if result = SE_ERR_NOASSOC
then
begin
(* if no duplicates as in case of calling the help file help\test2.ppx, invoke MCMsumatrapdf.exe; in other cases like View PDF show the message box *)
if paramstr(1) = 'help\test2.pxx'
then
begin
cmd:='MCMsumatrapdf.exe ';
cmd:=cmd+'"'+paramstr(1)+'"';
WinExec(pchar(cmd),SW_SHOWNORMAL);
end
else
MessageBox(0,'There is no application associated with a PDF file. Save your composition as PDF via MCMsumatrapdf or associate PDF files with a PDF viewer like Adobe Acrobat Reader or Foxit Reader.','No PDF file association!',MB_OK or MB_ICONINFORMATION)
end
else if (result = ERROR_FILE_NOT_FOUND) or (result = ERROR_PATH_NOT_FOUND)
then
MessageBox(0,'The pdf file cannot be found!','Error',MB_OK or MB_ICONERROR)
else if result < 33
then
MessageBox(0,'Cannot display the pdf file!','Error',MB_OK or MB_ICONERROR);
except
end;
end.