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);
28 // if a filename is given, convert it to a PChar; needed for the ShellExecute
29 if FileName <> '' then
30 Params:= PChar('"' + FileName + '"')
35 hLyX:= ShellExecute(hConsole,PChar('open'),
36 PChar(Path),Params,nil,SW_SHOWNORMAL);
37 if hLyX = ERROR_FILE_NOT_FOUND then
39 MessageDLG('The file'#13#10 + Path + #13#10
40 + 'could not be found!',mtError,[mbOK],0);
43 if hLyX = SE_ERR_ACCESSDENIED then
45 MessageDLG('Windows denied access on the file'#13#10 + Path,
53 procedure HideWindow(ProgWin: string);
54 // hides a given program window
59 // find handle of the program window
60 // Repeat until the handle is available
61 // because Lyx needs some time to start
63 Sleep(1000); // wait 1 second to give LyX time to open
64 Handle := FindWindow(nil,Pchar(ProgWin));
67 // hide the window from taskbar
68 ShowWindow(Handle, SW_HIDE);
75 //Read path to this application
78 //get handle of this console window
79 // This application is called by the lyx.bat with the name "LyX"
80 hConsole := FindWindow(nil,Pchar('LyX'));
81 // hide the window of this console application
82 ShowWindow(hConsole,SW_HIDE);
84 // do the same for the real name of this console application
85 // because it depends on the computer speed if the "LyX" console window
86 // was closed before it could be processed
87 hConsole := FindWindow(nil,Pchar(Path));
88 ShowWindow(hConsole,SW_HIDE);
90 // replace in the path "lyxLauncher.exe" by "lyx.exe"
91 Path:= StringReplace(Path, 'lyxLauncher', 'lyx', [rfIgnoreCase]);
93 // read given filename of a LyX-document
94 FileName:= ParamStr(1);
97 StartLyX(hConsole,FileName,Path);
99 // hide console window of lyx.exe