(***********************************************)
(*                                             *)
(* Win32 Console Application Demo              *)
(* Copyright (c) 1999 by TMT Development Corp. *)
(* Author: Vadim Bodrov, TMT Development Corp. *)
(*                                             *)
(* Targets:                                    *)
(*   Win32 only                                *)
(*                                             *)
(***********************************************)

{$ifndef __WIN32__}
  This program must be compiled as Win32 application only
{$endif}

// Console applications looks like the DOS programs but only looks..
// They allows one to easy access to all Win32 features.
// So, how about to bring a new life to your old text-mode programs?

uses Windows, MMSystem, {$ifdef __CON__} Crt {$else} WinCRT {$endif};
var
  Act:      Char;
  OrigMode: Word;
  isPlayed: Boolean := false;
  Mess:     String;
begin
  SetConsoleTitle('My first Win32 console application!');
  HideCursor;
{$ifdef __GUI__}
  TextBackground(Black);
  CloseOnExit := TRUE;
{$endif}
  ClrScr;
  TextColor(Yellow);
  GotoXY(22, 9); Writeln('This is a Win32 console application.');
  TextColor(LightGray);
  GotoXY(31, 10); Writeln('Choose an action:');
  TextColor(White);
  GotoXY(30, 12); Writeln('1 - play wave file');
  GotoXY(30, 13); Writeln('2 - play/stop MIDI file');
  GotoXY(30, 14); Writeln('3 - show message box');
  GotoXY(30, 15); Writeln('4 - show warning box');
  GotoXY(30, 16); Writeln('Esc - exit');
  repeat
    Act := ReadKey;
    case Act of
      '1': sndPlaySound('sample.wav', 1);
      '2': begin
             if not isPlayed then begin
               Mess := 'open sequencer!sample.mid alias my_midi' + #0;
               mciSendString(@Mess[1], nil, 0, 0);
               Mess := 'play my_midi' + #0;
               mciSendString(@Mess[1], nil, 0, 0);
             end else begin
               Mess := 'close my_midi' + #0;
               mciSendString(@Mess[1], nil, 0, 0);
             end;
             isPlayed := not isPlayed;
           end;
      '3': MessageBox(0, 'This program compiled with TMT Pascal',
             'This is simply message box', MB_OK);
      '4': MessageBoxEx(0, 'This program can be compiled for Win32 target only!',
             'This is warning box', MB_ICONWARNING or MB_TASKMODAL, LANG_NEUTRAL);
    end;
  until Act = #27;
  ShowCursor;
  Mess := 'close my_midi' + #0;
  mciSendString(@Mess[1], nil, 0, 0);
end.