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;
15 var Path,FileName : string;
19 procedure StartLyX(hConsole: THandle; FileName,Path: string);
26 // if a filename is given, convert it to a PChar; needed for the ShellExecute
27 if FileName <> '' then
28 Params:= PChar(FileName)
33 hLyX:= ShellExecute(hConsole,PChar('open'),
34 PChar(Path),Params,nil,SW_SHOWNORMAL);
35 if hLyX = ERROR_FILE_NOT_FOUND then
37 MessageDLG('The file'#13#10 + Path + #13#10
38 + 'could not be found!',mtError,[mbOK],0);
41 if hLyX = SE_ERR_ACCESSDENIED then
43 MessageDLG('Windows denied access on the file'#13#10 + Path,
51 procedure HideWindow(ProgWin: string);
52 // hides a given program window
57 // find handle of the program window
58 // Repeat until the handle is available
59 // because Lyx needs some time to start
61 Sleep(1000); // wait 1 second to give LyX time to open
62 Handle := FindWindow(nil,Pchar(ProgWin));
65 // hide the window from taskbar
66 ShowWindow(Handle, SW_HIDE);
73 //Read path to this application
76 //get handle of this console window
77 // This application is called by the lyx.bat with the name "LyX"
78 hConsole := FindWindow(nil,Pchar('LyX'));
79 // hide the window of this console application
80 ShowWindow(hConsole,SW_HIDE);
82 // do the same for the real name of this console application
83 // because it depends on the computer speed if the "LyX" console window
84 // was closed before it could be processed
85 hConsole := FindWindow(nil,Pchar(Path));
86 ShowWindow(hConsole,SW_HIDE);
88 // replace in the path "lyxLauncher.exe" by "lyx.exe"
89 Path:= StringReplace(Path, 'lyxLauncher', 'lyx', [rfIgnoreCase]);
91 // read given filename of a LyX-document
92 FileName:= ParamStr(1);
95 StartLyX(hConsole,FileName,Path);
97 // hide console window of lyx.exe