From: victorddm@delphi.com
Newsgroups: comp.lang.pascal
Subject: Re: Delphi: Switch To
Date: Thu, 4 May 95 13:50:49 -0500

>Is it possible to call the windows Switch To function? Rather than pressing
>control+esc or using the - menu I'd like to call it from a speed button or
>a popup menu, is this possible?
>
>Another question, what is the best way to play *.wav files? Currently I'm
>
 
Gilbert, here is a small Delphi project that does both things:
 
unit Unit1;
 
interface
 
uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, MMSystem, StdCtrls, FileCtrl;
 
type
  TForm1 = class(TForm)
    Button1: TButton;
    FileListBox1: TFileListBox;
    DirectoryListBox1: TDirectoryListBox;
    DriveComboBox1: TDriveComboBox;
    Edit1: TEdit;
    Label1: TLabel;
    Button2: TButton;
    procedure DirectoryListBox1Change(Sender: TObject);
    procedure DriveComboBox1Change(Sender: TObject);
    procedure Edit1Change(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
 
var
  Form1: TForm1;
 
implementation
 
{$R *.DFM}
 
procedure TForm1.DirectoryListBox1Change(Sender: TObject);
begin
  FileListBox1.Directory:=DirectoryListBox1.Directory;
end;
 
procedure TForm1.DriveComboBox1Change(Sender: TObject);
begin
  DirectoryListBox1.Drive:=DriveComboBox1.Drive;
end;
 
procedure TForm1.Edit1Change(Sender: TObject);
begin
     FileListBox1.Mask:=edit1.text;
end;
 
procedure TForm1.Button1Click(Sender: TObject);
var
  szFileName : array [0..12] of char;
begin
  StrPCopy(szFileName,FileListBox1.Items[FileListBox1.ItemIndex]);
  sndPlaySound(szFileName,SND_SYNC);
 
end;
 
procedure TForm1.Button2Click(Sender: TObject);
begin
  WinExec('TASKMAN.EXE',SW_SHOW);
end;
 
end.
 
-------------------------------------
 
The key to play wave file is to call the function "sndPlaySound" located
in the MMSYSTEM unit (look at the USES clause).
 
This is the ASCII representation of my form :
 
object Form1: TForm1
  Left = 200
  Top = 99
  Width = 435
  Height = 300
  Caption = 'Form1'
  Font.Color = clWindowText
  Font.Height = -13
  Font.Name = 'System'
  Font.Style = []
  PixelsPerInch = 96
  TextHeight = 16
  object Label1: TLabel
    Left = 8
    Top = 176
    Width = 96
    Height = 16
    Caption = 'List Files Type'
  end
  object Button1: TButton
    Left = 161
    Top = 184
    Width = 136
    Height = 33
    Caption = 'Play'
    TabOrder = 0
    OnClick = Button1Click
  end
  object FileListBox1: TFileListBox
    Left = 8
    Top = 8
    Width = 137
    Height = 161
    ItemHeight = 16
    Mask = '*.wav'
    TabOrder = 1
  end
  object DirectoryListBox1: TDirectoryListBox
    Left = 152
    Top = 8
    Width = 145
    Height = 129
    ItemHeight = 16
    TabOrder = 2
    OnChange = DirectoryListBox1Change
  end
  object DriveComboBox1: TDriveComboBox
    Left = 152
    Top = 144
    Width = 145
    Height = 22
    TabOrder = 3
    OnChange = DriveComboBox1Change
  end
  object Edit1: TEdit
    Left = 8
    Top = 192
    Width = 137
    Height = 25
    TabOrder = 4
    Text = '*.WAV'
    OnChange = Edit1Change
  end
  object Button2: TButton
    Left = 161
    Top = 224
    Width = 136
    Height = 33
    Caption = 'Run Task Mgr'
    TabOrder = 5
    OnClick = Button2Click
  end
end
 
--------------------
 
 
Enjoy it,
 
--Victor J. DuLuc
