VTIStartUnit.pas 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. {
  2. TIGCC IDE
  3. Copyright (C) 2000-2004 Sebastian Reichelt
  4. Copyright (C) 2006 Kevin Kofler
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2, or (at your option)
  8. any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software Foundation,
  15. Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  16. }
  17. unit VTIStartUnit;
  18. interface
  19. uses
  20. MasterUnit,
  21. Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  22. StdCtrls, ExtCtrls;
  23. type
  24. TVTIStartForm = class(TForm)
  25. Label1: TLabel;
  26. CancelButton: TButton;
  27. FindTimer: TTimer;
  28. procedure FormShow(Sender: TObject);
  29. procedure FormClose(Sender: TObject; var Action: TCloseAction);
  30. procedure FindTimerTimer(Sender: TObject);
  31. private
  32. ProcessHandle: THandle;
  33. public
  34. VTIWindow: HWnd;
  35. VTIType: TVTICalcType;
  36. end;
  37. implementation
  38. {$R *.DFM}
  39. uses
  40. UtilsWin;
  41. procedure TVTIStartForm.FormShow(Sender: TObject);
  42. var
  43. StartupInfo: TStartupInfo;
  44. ProcessInfo: TProcessInformation;
  45. begin
  46. FillChar (StartupInfo, SizeOf (StartupInfo), 0);
  47. StartupInfo.cb := SizeOf (StartupInfo);
  48. if CreateProcess (nil, PChar (VTIPath), nil, nil, False, CREATE_NEW_PROCESS_GROUP or DETACHED_PROCESS, nil, PChar (ExtractFilePath (VTIPath)), StartupInfo, ProcessInfo) then begin
  49. ProcessHandle := ProcessInfo.hProcess;
  50. CloseHandle (ProcessInfo.hThread);
  51. end else begin
  52. ShowDefaultMessageBox ('An error occurred while trying to start Virtual TI.', 'Error', mtProgramError);
  53. ModalResult := mrAbort;
  54. end;
  55. end;
  56. procedure TVTIStartForm.FormClose(Sender: TObject;
  57. var Action: TCloseAction);
  58. begin
  59. if ProcessHandle <> 0 then
  60. CloseHandle (ProcessHandle);
  61. end;
  62. procedure TVTIStartForm.FindTimerTimer(Sender: TObject);
  63. var
  64. ExitCode: Cardinal;
  65. begin
  66. if GetExitCodeProcess (ProcessHandle, ExitCode) then begin
  67. if ExitCode <> STILL_ACTIVE then begin
  68. ModalResult := mrAbort;
  69. Exit;
  70. end;
  71. end;
  72. VTIWindow := FindWindow ('TEmuWnd', 'Virtual TI-89');
  73. if VTIWindow = 0 then begin
  74. VTIWindow := FindWindow ('TEmuWnd', 'Virtual TI-92+');
  75. if VTIWindow <> 0 then
  76. VTIType := cvVTITI92Plus;
  77. end else
  78. VTIType := cvVTITI89;
  79. if VTIWindow <> 0 then
  80. ModalResult := mrOK;
  81. end;
  82. end.