Witam! Mam taki problem mam przyciski wstawione w zwykłym builderze ale większość funkcji obsługuje poleceniami API. Chciałbym zamapować klawisze tzn pod te przyciski wstawione w bulderze chciałbym wstawić odpowiednie klawisze ze po naciśnięciu jakiegoś stanie się to samo co po kliknięciu na przycisk! Chciałbym to zrobić w API, może mi ktoś w tym pomóc zamieszczam poszczególne listingi...

__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}

void fastcall TForm1::Button1Click(TObject *Sender)
{
mciSendString("set cdaudio door open wait",NULL,0,0);
}
//---------------------------------------------------------------------------
void
fastcall TForm1::Button2Click(TObject *Sender)
{
mciSendString("set cdaudio door closed wait",NULL,0,0);
}
//---------------------------------------------------------------------------

#include "cd.h"

void __fastcall TForm1::Button3Click(TObject *Sender)
{
//-----------------------------------

//----------------------------------
OpenCD((AnsiString)DriveComboBox1->Drive+":");
}
//---------------------------------------------------------------------------
void fastcall TForm1::Button4Click(TObject *Sender)
{
CloseCD((AnsiString)DriveComboBox1->Drive+":");
}
//---------------------------------------------------------------------------
void
fastcall TForm1::Button5Click(TObject Sender)
{
switch (StanCDAudio((AnsiString)DriveComboBox1->Drive+":"))
{
case 1242348: ShowMessage("Symbol nie wskazuje napędu CD"); break;
case 1242732: ShowMessage("Brak napędu CD"); break;
case 530: ShowMessage("Brak płyty"); break;
case 525: ShowMessage("Zatrzymany"); break;
case 526: ShowMessage("Odtwarzanie"); break;
default: ShowMessage(IntToStr(StanCDAudio((AnsiString)DriveComboBox1->Drive+":"))); break;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button6Click(TObject
Sender)
{
ShowMessage((IsCDAudio((AnsiString)DriveComboBox1->Drive+":"))?"Tak":"Nie");
}
//---------------------------------------------------------------------------
void fastcall TForm1::Button7Click(TObject *Sender)
{
PlayCDAudio((AnsiString)DriveComboBox1->Drive+":");
}
//---------------------------------------------------------------------------
void
fastcall TForm1::Button8Click(TObject Sender)
{
PauseCDAudio((AnsiString)DriveComboBox1->Drive+":");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button9Click(TObject
Sender)
{
ResumeCDAudio((AnsiString)DriveComboBox1->Drive+":");
}
//---------------------------------------------------------------------------
void fastcall TForm1::Button10Click(TObject *Sender)
{
StopCDAudio((AnsiString)DriveComboBox1->Drive+":");
}
//---------------------------------------------------------------------------
void
fastcall TForm1::Button11Click(TObject *Sender)
{
OpenDialog1->FileName=Edit1->Text;
if (OpenDialog1->Execute())
{
Edit1->Text=OpenDialog1->FileName;
}
}
//---------------------------------------------------------------------------

#include <mmsystem.h>

void __fastcall TForm1::Button12Click(TObject *Sender)
{
PlaySound(Edit1->Text.c_str(),0,SND_FILENAME | SND_ASYNC);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button13Click(TObject *Sender)
{
PlaySound(NULL,0,0);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button14Click(TObject *Sender)
{
if (waveOutGetNumDevs==0) ShowMessage("Brak karty dźwiękowej!");
else ShowMessage("Karty dźwiękowa jest zainstalowana");
}
//---------------------------------------------------------------------------

void UstalPoziomGlosnosciWave(unsigned short kanalLewy,unsigned short kanalPrawy)
{
unsigned long glosnosc=(kanalLewy << 24) | (kanalPrawy << 8);
waveOutSetVolume((HWAVEOUT)WAVE_MAPPER,glosnosc);
}

void CzytajPoziomGlosnosciWave(unsigned short& kanalLewy,unsigned short& kanalPrawy)
{
unsigned long glosnosc;
waveOutGetVolume((HWAVEOUT)WAVE_MAPPER,&glosnosc);
kanalLewy=(unsigned short)((glosnosc & 0xFFFF0000) >> 24);
kanalPrawy=(unsigned short)((glosnosc & 0x0000FFFF) >> 8);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::TrackBar1Change(TObject *Sender)
{
UstalPoziomGlosnosciWave(TrackBar1->Position,TrackBar2->Position);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::TrackBar3Change(TObject *Sender)
{
UstalPoziomGlosnosciCDAudio(TrackBar3->Position,TrackBar4->Position);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormCreate(TObject *Sender)
{
unsigned short lewy,prawy;
CzytajPoziomGlosnosciWave(lewy,prawy);
TrackBar1->Position=(int)lewy;
TrackBar2->Position=(int)prawy;

CzytajPoziomGlosnosciCDAudio(lewy,prawy);
TrackBar3->Position=(int)lewy;
TrackBar4->Position=(int)prawy;

}
//---------------------------------------------------------------------------

plik cd.cpp

#include <winsock2.h>
#include <windows.h>
#include <stdio.h>

#pragma hdrstop

#include "cd.h"

//---------------------------------------------------------------------------

#pragma package(smart_init)

#include <mmsystem.h>

bool KontrolaTackiCD(AnsiString Drive,bool Operacja)
{

bool Wynik=false;

MCI_OPEN_PARMS parametry;
parametry.dwCallback=0; //uchwyt okna, do ktorego moglyby byc wysylane komunikaty powiadamiajace o wysunieciu tacki
parametry.lpstrDeviceType="CDAudio";
parametry.lpstrElementName=Drive.c_str(); //Symbol dysku w formacie X:

//Inicjalizacja urzadzenia
//mciSendCommand(0,MCI_OPEN,MCI_OPEN_ELEMENT | MCI_OPEN_TYPE,(long)&parametry);
MCIERROR mciBlad=mciSendCommand(0,MCI_OPEN,MCI_OPEN_ELEMENT | MCI_OPEN_TYPE,(long)&parametry);
if (mciBlad!=0)
{
    char opisBledu[MAXERRORLENGTH];
    mciGetErrorString(mciBlad,opisBledu,MAXERRORLENGTH);
    ShowMessage(opisBledu);
    return false;
}

if (Operacja)
    //Otwieranie napedu CDROM
       Wynik=(mciSendCommand(parametry.wDeviceID,MCI_SET,MCI_SET_DOOR_OPEN,0)==0);

else
    //Zamykanie napedu CDROM
    Wynik=(mciSendCommand(parametry.wDeviceID,MCI_SET,MCI_SET_DOOR_CLOSED,0)==0);

//zwolnienie dostepu do urzadzenia
mciSendCommand(parametry.wDeviceID,MCI_CLOSE,MCI_NOTIFY,(long)&parametry);

return Wynik;

}

bool OpenCD(AnsiString Drive)
{

return KontrolaTackiCD(Drive,true);

}

bool CloseCD(AnsiString Drive)
{
return KontrolaTackiCD(Drive,false);
}

//---------------------------------------------------------------------------

int StanCDAudio(AnsiString Drive)
{
MCI_OPEN_PARMS parametry;
parametry.dwCallback=0;
parametry.lpstrDeviceType="CDAudio";
parametry.lpstrElementName=Drive.c_str(); //Litera dysku musi byc np. "X:"
mciSendCommand(0,MCI_OPEN,MCI_OPEN_ELEMENT | MCI_OPEN_TYPE,(long)&parametry);

MCI_STATUS_PARMS stan;
stan.dwItem=MCI_STATUS_MODE;
mciSendCommand(parametry.wDeviceID,MCI_STATUS,MCI_WAIT | MCI_STATUS_ITEM,(long)&stan);
int Wynik=stan.dwReturn; //stan MCI zaczyna sie od 524

mciSendCommand(parametry.wDeviceID,MCI_CLOSE,MCI_NOTIFY,(long)&parametry);
return Wynik;

}

//---------------------------------------------------------------------------

bool IsCDAudio(AnsiString Drive)
{
MCI_OPEN_PARMS parametry;
parametry.dwCallback=0;
parametry.lpstrDeviceType="CDAudio";
parametry.lpstrElementName=Drive.c_str();
MCIERROR mciBlad=mciSendCommand(0,MCI_OPEN,MCI_OPEN_ELEMENT | MCI_OPEN_TYPE,(long)&parametry);
if (mciBlad!=0) return false;

MCI_STATUS_PARMS stanNapedu;
stanNapedu.dwCallback=0;
stanNapedu.dwItem=MCI_CDA_STATUS_TYPE_TRACK;
stanNapedu.dwTrack=1;
mciBlad=mciSendCommand(parametry.wDeviceID,MCI_STATUS,MCI_TRACK | MCI_STATUS_ITEM,(long)&stanNapedu);
if (mciBlad!=0) return false;

bool Wynik;
switch (stanNapedu.dwReturn)
{
    case MCI_CDA_TRACK_AUDIO: Wynik=true; break;
    default: Wynik=false; break;
}

mciSendCommand(parametry.wDeviceID,MCI_CLOSE,MCI_NOTIFY,(long)&parametry);
return Wynik;

}

//---------------------------------------------------------------------------

bool KontrolaCDAudio(AnsiString Drive,unsigned long Operacja)
{
MCI_OPEN_PARMS parametry;
parametry.dwCallback=0;
parametry.lpstrDeviceType="CDAudio";
parametry.lpstrElementName=Drive.c_str(); //Litera dysku musi byc np. "X:"
mciSendCommand(0,MCI_OPEN,MCI_OPEN_ELEMENT | MCI_OPEN_TYPE,(long)&parametry);

bool Wynik=(mciSendCommand(parametry.wDeviceID,Operacja,0,0)==0);

mciSendCommand(parametry.wDeviceID,MCI_CLOSE,MCI_NOTIFY,(long)&parametry);
return Wynik;

}

bool PlayCDAudio(AnsiString Drive)
{
return KontrolaCDAudio(Drive,MCI_PLAY);
}

bool ResumeCDAudio(AnsiString Drive)
{
return KontrolaCDAudio(Drive,MCI_RESUME);
}

bool PauseCDAudio(AnsiString Drive)
{
if (StanCDAudio(Drive)!=525) return KontrolaCDAudio(Drive,MCI_PAUSE); //gdy odtwarzanie
else return ResumeCDAudio(Drive); //gdy zatrzymany
}

bool StopCDAudio(AnsiString Drive)
{

return KontrolaCDAudio(Drive,MCI_STOP);

}

bool UstalPoziomGlosnosciCDAudio(unsigned short kanalLewy,unsigned short kanalPrawy)
{
unsigned long glosnosc=(kanalLewy << 24) | (kanalPrawy << 8);
return (auxSetVolume(AUX_MAPPER,glosnosc)==MMSYSERR_NOERROR);
}

bool CzytajPoziomGlosnosciCDAudio(unsigned short& kanalLewy,unsigned short& kanalPrawy)
{
unsigned long glosnosc;
bool Wynik=(auxGetVolume(AUX_MAPPER,&glosnosc)==MMSYSERR_NOERROR);
kanalLewy=(unsigned short)((glosnosc & 0xFFFF0000) >> 24);
kanalPrawy=(unsigned short)((glosnosc & 0x0000FFFF) >> 8);
return Wynik;
}

</cpp></email>