VTIStartUnit.pas 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. unit VTIStartUnit;
  2. interface
  3. uses
  4. MasterUnit,
  5. Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  6. StdCtrls, ExtCtrls;
  7. type
  8. TVTIStartForm = class(TForm)
  9. Label1: TLabel;
  10. CancelButton: TButton;
  11. FindTimer: TTimer;
  12. procedure FormShow(Sender: TObject);
  13. procedure FormClose(Sender: TObject; var Action: TCloseAction);
  14. procedure FindTimerTimer(Sender: TObject);
  15. private
  16. ProcessHandle: THandle;
  17. public
  18. VTIWindow: HWnd;
  19. VTIType: TCurVTIType;
  20. end;
  21. implementation
  22. {$R *.DFM}
  23. uses
  24. UtilsWin;
  25. procedure TVTIStartForm.FormShow(Sender: TObject);
  26. var
  27. StartupInfo: TStartupInfo;
  28. ProcessInfo: TProcessInformation;
  29. begin
  30. FillChar (StartupInfo, SizeOf (StartupInfo), 0);
  31. StartupInfo.cb := SizeOf (StartupInfo);
  32. if CreateProcess (nil, PChar (VTIPath), nil, nil, False, CREATE_NEW_PROCESS_GROUP or DETACHED_PROCESS, nil, PChar (ExtractFilePath (VTIPath)), StartupInfo, ProcessInfo) then begin
  33. ProcessHandle := ProcessInfo.hProcess;
  34. CloseHandle (ProcessInfo.hThread);
  35. end else begin
  36. ShowDefaultMessageBox ('An error occurred while trying to start Virtual TI.', 'Error', mtProgramError);
  37. ModalResult := mrAbort;
  38. end;
  39. end;
  40. procedure TVTIStartForm.FormClose(Sender: TObject;
  41. var Action: TCloseAction);
  42. begin
  43. if ProcessHandle <> 0 then
  44. CloseHandle (ProcessHandle);
  45. end;
  46. procedure TVTIStartForm.FindTimerTimer(Sender: TObject);
  47. var
  48. ExitCode: Cardinal;
  49. begin
  50. if GetExitCodeProcess (ProcessHandle, ExitCode) then begin
  51. if ExitCode <> STILL_ACTIVE then begin
  52. ModalResult := mrAbort;
  53. Exit;
  54. end;
  55. end;
  56. VTIWindow := FindWindow ('TEmuWnd', 'Virtual TI-89');
  57. if VTIWindow = 0 then begin
  58. VTIWindow := FindWindow ('TEmuWnd', 'Virtual TI-92+');
  59. if VTIWindow <> 0 then
  60. VTIType := cvTI92Plus;
  61. end else
  62. VTIType := cvTI89;
  63. if VTIWindow <> 0 then
  64. ModalResult := mrOK;
  65. end;
  66. end.