Título: Tocando Waves à partir dos recursos.
Linguagem: C++Builder
S.O.: Windows
Autor(es): Wenderson Teixeira


Tocando Waves à partir dos recursos.


MainFrm.h
//---------------------------------------------------------------------------
#ifndef MainFrmH
#define MainFrmH
//---------------------------------------------------------------------------
#include <vcl\Classes.hpp>
#include <vcl\Controls.hpp>
#include <vcl\StdCtrls.hpp>
#include <vcl\Forms.hpp>
#include <vcl\ExtCtrls.hpp>
//---------------------------------------------------------------------------
class TMainForm : public TForm
{
__published:  // IDE-managed Components
  TButton *ExitBtn;
  TButton *Play1Btn;
  TButton *Play2Btn;
  TPanel *Panel1;
  TLabel *Label1;
  void __fastcall ExitBtnClick(TObject *Sender);
  void __fastcall Play1BtnClick(TObject *Sender);
  void __fastcall Play2BtnClick(TObject *Sender);
  
  
private:  // User declarations
public:    // User declarations
  __fastcall TMainForm(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern TMainForm *MainForm;
//---------------------------------------------------------------------------
#endif

MainFrm.cpp
//---------------------------------------------------------------------------
#include <vcl\vcl.h>
#pragma hdrstop

#include <mmsystem.h>

#include "MainFrm.h"
//---------------------------------------------------------------------------
#pragma resource "*.dfm"
TMainForm *MainForm;
//---------------------------------------------------------------------------
__fastcall TMainForm::TMainForm(TComponent* Owner)
  : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::ExitBtnClick(TObject *Sender)
{
  Close();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::Play1BtnClick(TObject *Sender)
{
  if(!PlaySound(MAKEINTRESOURCE(100), HInstance, SND_ASYNC | SND_RESOURCE | SND_NOWAIT | SND_NODEFAULT))
    Application->MessageBox("Erro ao tentar tocar som 1.", 0, MB_ICONEXCLAMATION);
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::Play2BtnClick(TObject *Sender)
{
  if(!PlaySound("WAVERC2", HInstance, SND_ASYNC | SND_RESOURCE | SND_NOWAIT | SND_NODEFAULT))
    Application->MessageBox("Erro ao tentar tocar som 2.", 0, MB_ICONEXCLAMATION);
}
//---------------------------------------------------------------------------

MainFrm.dfm
object MainForm: TMainForm
  Left = 193
  Top = 109
  Width = 409
  Height = 197
  Caption = 'WaveRC'
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  PixelsPerInch = 96
  TextHeight = 13
  object ExitBtn: TButton
    Left = 8
    Top = 136
    Width = 75
    Height = 25
    Caption = 'Sai&r'
    TabOrder = 0
    OnClick = ExitBtnClick
  end
  object Play1Btn: TButton
    Left = 8
    Top = 8
    Width = 75
    Height = 25
    Caption = 'Tocar Som &1'
    TabOrder = 1
    OnClick = Play1BtnClick
  end
  object Play2Btn: TButton
    Left = 8
    Top = 40
    Width = 75
    Height = 25
    Caption = 'Tocar Som &2'
    TabOrder = 2
    OnClick = Play2BtnClick
  end
  object Panel1: TPanel
    Left = 88
    Top = 8
    Width = 305
    Height = 153
    BevelOuter = bvLowered
    TabOrder = 3
    object Label1: TLabel
      Left = 16
      Top = 16
      Width = 281
      Height = 121
      Alignment = taCenter
      AutoSize = False
      Caption = 'Programa exemplo de como tocar sons à partir de recursos.'#10#10'feito por'#10' Wenderson Teixeira'
      Font.Charset = ANSI_CHARSET
      Font.Color = clBlack
      Font.Height = -19
      Font.Name = 'MS Sans Serif'
      Font.Style = []
      ParentFont = False
      WordWrap = True
    end
  end
end

Waves.rc

#define WAVERC1 100

WAVERC1 WAVE "c:/windows/media/ringin.wav"
WAVERC2 WAVE "c:/windows/media/ringout.wav"






1