Advertisement
agul

CD Open / CD Close

Feb 16th, 2012
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 2.22 KB | None | 0 0
  1. program Project2;
  2.  
  3. uses
  4.   Windows,
  5.   SysUtils,
  6.   MMSystem;
  7.  
  8. var
  9. c:char;
  10. i,n:longint;
  11. A:array [1..1000] of longint;
  12.  
  13. function OpenCD(Drive: Char): Boolean;
  14. var
  15.  
  16.   Res: MciError;
  17.   OpenParm: TMCI_Open_Parms;
  18.   Flags: DWord;
  19.   S: string;
  20.   DeviceID: Word;
  21. begin
  22.  
  23.   Result := false;
  24.   S := Drive + ':';
  25.   Flags := mci_Open_Type or mci_Open_Element;
  26.   with OpenParm do
  27.   begin
  28.     dwCallback := 0;
  29.     lpstrDeviceType := 'CDAudio';
  30.     lpstrElementName := PChar(S);
  31.   end;
  32.   Res := mciSendCommand(0, mci_Open, Flags, Longint(@OpenParm));
  33.   if Res <> 0 then
  34.     exit;
  35.   DeviceID := OpenParm.wDeviceID;
  36.   try
  37.     Res := mciSendCommand(DeviceID, MCI_SET, MCI_SET_DOOR_OPEN, 0);
  38.     if Res = 0 then
  39.       exit;
  40.     Result := True;
  41.   finally
  42.     mciSendCommand(DeviceID, mci_Close, Flags, Longint(@OpenParm));
  43.   end;
  44. end;
  45.  
  46. function CloseCD(Drive: Char): Boolean;
  47. var
  48.  
  49.   Res: MciError;
  50.   OpenParm: TMCI_Open_Parms;
  51.   Flags: DWord;
  52.   S: string;
  53.   DeviceID: Word;
  54. begin
  55.  
  56.   Result := false;
  57.   S := Drive + ':';
  58.   Flags := mci_Open_Type or mci_Open_Element;
  59.   with OpenParm do
  60.   begin
  61.     dwCallback := 0;
  62.     lpstrDeviceType := 'CDAudio';
  63.     lpstrElementName := PChar(S);
  64.   end;
  65.   Res := mciSendCommand(0, mci_Open, Flags, Longint(@OpenParm));
  66.   if Res <> 0 then
  67.     exit;
  68.   DeviceID := OpenParm.wDeviceID;
  69.   try
  70.     Res := mciSendCommand(DeviceID, MCI_SET, MCI_SET_DOOR_CLOSED, 0);
  71.     if Res = 0 then
  72.       exit;
  73.     Result := True;
  74.   finally
  75.     mciSendCommand(DeviceID, mci_Close, Flags, Longint(@OpenParm));
  76.   end;
  77. end;
  78.  
  79.  
  80. begin
  81. if fileexists('C:\Class\11e\params.txt') then
  82. begin
  83. assign(input,'C:\Class\11e\params.txt');
  84. reset(input);
  85. readln(n);
  86. for i:=1 to n do readln(A[i]);
  87. // -1 CLOSE CD
  88. // -2 OPEN CD
  89. // X  WAIT X ms
  90. close(input);
  91. while 1=1 do
  92.  begin
  93.   for i:=1 to n do
  94.    begin
  95.     if A[i]=-1 then begin for c:='A' to 'Z' do closecd(c); end else
  96.     if A[i]=-2 then begin for c:='A' to 'Z' do opencd(c); end else
  97.     sleep(A[i]);
  98.    end;
  99.  end;
  100. end else
  101. while 1=1 do begin
  102. for c:='A' to 'Z' do begin
  103. OpenCD(c);
  104. CloseCD(c);  end;
  105. sleep(1000*60*5);
  106. end;
  107.   { TODO -oUser -cConsole Main : Insert code here }
  108. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement