2 // this program opens LyX and hides its console window
5 {The problematic is the following:
6 When the lyx.exe is started, also a console window is shown.
7 But closing the console window, also closes LyX,
8 therefore the console will be hidden by this program.}
13 Windows, SysUtils, ShellApi, Dialogs;
17 var Path,FileName : string;
21 procedure StartLyX(hConsole: THandle; FileName,Path: string);
29 // if a filename is given, quote it to avoid the path with spaces problem
30 if FileName <> '' then
31 Params:= PChar('"' + FileName + '"')
35 // get folder of the lyx.exe
36 Folder:= StringReplace(Path,'\lyx.exe','',[rfIgnoreCase]);
37 // quote path to avoid the path with spaces problem
38 Folder:= '"' + Folder + '"';
41 hLyX:= ShellExecute(hConsole,PChar('open'),PChar(Path),
42 Params,PChar(Folder),SW_SHOWNORMAL);
43 if hLyX = ERROR_FILE_NOT_FOUND then
45 MessageDLG('The file'#13#10 + Path + #13#10
46 + 'could not be found!',mtError,[mbOK],0);
49 if hLyX = SE_ERR_ACCESSDENIED then
51 MessageDLG('Windows denied access on the file'#13#10 + Path,
59 procedure HideWindow(ProgWin: string);
60 // hides a given program window
65 // find handle of the program window
66 // Repeat until the handle is available
67 // because Lyx needs some time to start
69 Sleep(1000); // wait 1 second to give LyX time to open
70 Handle := FindWindow(nil,Pchar(ProgWin));
73 // hide the window from taskbar
74 ShowWindow(Handle, SW_HIDE);
81 //Read path to this application
84 //get handle of this console window
85 // This application is called by the lyx.bat with the name "LyX"
86 hConsole := FindWindow(nil,Pchar('LyX'));
87 // hide the window of this console application
88 ShowWindow(hConsole,SW_HIDE);
90 // do the same for the real name of this console application
91 // because it depends on the computer speed if the "LyX" console window
92 // was closed before it could be processed
93 hConsole := FindWindow(nil,Pchar(Path));
94 ShowWindow(hConsole,SW_HIDE);
96 // replace in the path "lyxLauncher.exe" by "lyx.exe"
97 Path:= StringReplace(Path, 'lyxLauncher', 'lyx', [rfIgnoreCase]);
99 // read given filename of a LyX-document
100 FileName:= ParamStr(1);
103 StartLyX(hConsole,FileName,Path);
105 // hide console window of lyx.exe