2007-05-20 01:12:40 +00:00
|
|
|
|
program lyxLauncher;
|
|
|
|
|
// this program opens LyX and hides its console window
|
|
|
|
|
// author: Uwe St<53>hr
|
|
|
|
|
|
|
|
|
|
{The problematic is the following:
|
|
|
|
|
When the lyx.exe is started, also a console window is shown.
|
|
|
|
|
But closing the console window, also closes LyX,
|
|
|
|
|
therefore the console will be hidden by this program.}
|
|
|
|
|
|
|
|
|
|
{$APPTYPE CONSOLE}
|
|
|
|
|
|
|
|
|
|
uses
|
2007-05-20 14:06:34 +00:00
|
|
|
|
Windows, SysUtils, ShellApi, Dialogs;
|
2007-05-20 01:12:40 +00:00
|
|
|
|
|
2007-05-20 20:35:35 +00:00
|
|
|
|
{$R *.res}
|
|
|
|
|
|
2007-05-20 14:06:34 +00:00
|
|
|
|
var Path,FileName : string;
|
|
|
|
|
hConsole : THandle;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
procedure StartLyX(hConsole: THandle; FileName,Path: string);
|
|
|
|
|
// starts LyX
|
|
|
|
|
|
|
|
|
|
var Params : PChar;
|
2007-05-20 01:12:40 +00:00
|
|
|
|
hLyX : THandle;
|
2007-05-20 14:06:34 +00:00
|
|
|
|
begin
|
|
|
|
|
|
|
|
|
|
// if a filename is given, convert it to a PChar; needed for the ShellExecute
|
|
|
|
|
if FileName <> '' then
|
2007-05-20 20:35:35 +00:00
|
|
|
|
Params:= PChar('"' + FileName + '"')
|
2007-05-20 14:06:34 +00:00
|
|
|
|
else
|
|
|
|
|
Params:= nil;
|
|
|
|
|
|
|
|
|
|
// start LyX
|
|
|
|
|
hLyX:= ShellExecute(hConsole,PChar('open'),
|
|
|
|
|
PChar(Path),Params,nil,SW_SHOWNORMAL);
|
|
|
|
|
if hLyX = ERROR_FILE_NOT_FOUND then
|
|
|
|
|
begin
|
|
|
|
|
MessageDLG('The file'#13#10 + Path + #13#10
|
|
|
|
|
+ 'could not be found!',mtError,[mbOK],0);
|
|
|
|
|
exit;
|
|
|
|
|
end;
|
|
|
|
|
if hLyX = SE_ERR_ACCESSDENIED then
|
|
|
|
|
begin
|
|
|
|
|
MessageDLG('Windows denied access on the file'#13#10 + Path,
|
|
|
|
|
mtError,[mbOK],0);
|
|
|
|
|
exit;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
end; // end procedure
|
|
|
|
|
|
2007-05-20 01:12:40 +00:00
|
|
|
|
|
|
|
|
|
procedure HideWindow(ProgWin: string);
|
|
|
|
|
// hides a given program window
|
2007-05-20 14:06:34 +00:00
|
|
|
|
|
|
|
|
|
var Handle : THandle;
|
2007-05-20 01:12:40 +00:00
|
|
|
|
begin
|
|
|
|
|
|
|
|
|
|
// find handle of the program window
|
|
|
|
|
// Repeat until the handle is available
|
|
|
|
|
// because Lyx needs some time to start
|
|
|
|
|
Repeat
|
2007-05-20 14:06:34 +00:00
|
|
|
|
Sleep(1000); // wait 1 second to give LyX time to open
|
2007-05-20 01:12:40 +00:00
|
|
|
|
Handle := FindWindow(nil,Pchar(ProgWin));
|
|
|
|
|
Until Handle <> 0;
|
2007-05-20 14:06:34 +00:00
|
|
|
|
|
2007-05-20 01:12:40 +00:00
|
|
|
|
// hide the window from taskbar
|
|
|
|
|
ShowWindow(Handle, SW_HIDE);
|
|
|
|
|
|
|
|
|
|
end; //end procedure
|
|
|
|
|
|
|
|
|
|
|
2007-05-20 14:06:34 +00:00
|
|
|
|
begin //begin program
|
2007-05-20 01:12:40 +00:00
|
|
|
|
|
2007-05-20 14:06:34 +00:00
|
|
|
|
//Read path to this application
|
|
|
|
|
Path:= ParamStr(0);
|
2007-05-20 01:12:40 +00:00
|
|
|
|
|
2007-05-20 14:06:34 +00:00
|
|
|
|
//get handle of this console window
|
|
|
|
|
// This application is called by the lyx.bat with the name "LyX"
|
|
|
|
|
hConsole := FindWindow(nil,Pchar('LyX'));
|
|
|
|
|
// hide the window of this console application
|
|
|
|
|
ShowWindow(hConsole,SW_HIDE);
|
2007-05-20 01:12:40 +00:00
|
|
|
|
|
2007-05-20 14:06:34 +00:00
|
|
|
|
// do the same for the real name of this console application
|
|
|
|
|
// because it depends on the computer speed if the "LyX" console window
|
|
|
|
|
// was closed before it could be processed
|
|
|
|
|
hConsole := FindWindow(nil,Pchar(Path));
|
|
|
|
|
ShowWindow(hConsole,SW_HIDE);
|
2007-05-20 01:12:40 +00:00
|
|
|
|
|
2007-05-20 14:06:34 +00:00
|
|
|
|
// replace in the path "lyxLauncher.exe" by "lyx.exe"
|
|
|
|
|
Path:= StringReplace(Path, 'lyxLauncher', 'lyx', [rfIgnoreCase]);
|
2007-05-20 01:12:40 +00:00
|
|
|
|
|
2007-05-20 14:06:34 +00:00
|
|
|
|
// read given filename of a LyX-document
|
|
|
|
|
FileName:= ParamStr(1);
|
2007-05-20 01:12:40 +00:00
|
|
|
|
|
|
|
|
|
// start LyX
|
2007-05-20 14:06:34 +00:00
|
|
|
|
StartLyX(hConsole,FileName,Path);
|
2007-05-20 01:12:40 +00:00
|
|
|
|
|
|
|
|
|
// hide console window of lyx.exe
|
|
|
|
|
HideWindow(Path);
|
|
|
|
|
|
|
|
|
|
end. //end program
|
|
|
|
|
|