Академический Документы
Профессиональный Документы
Культура Документы
//--------------------------------------------------------------------------#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//--------------------------------------------------------------------------#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
float cambio[20];
//--------------------------------------------------------------------------__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//--------------------------------------------------------------------------void __fastcall TForm1::FormCreate(TObject *Sender)
{
ComboBox1->Items->Add("Dolares");
ComboBox1->Items->Add("Marcos Alemanes");
ComboBox1->Items->Add("Francos Suizos");
ComboBox1->Items->Add("Francos Alemanes");
ComboBox1->Items->Add("Libras Esterlinas");
cambio[0]=154.2;
cambio[1]=970.3;
cambio[2]=108.30;
cambio[3]=23.2;
cambio[4]=164.2;
}
//--------------------------------------------------------------------------void __fastcall TForm1::Button1Click(TObject *Sender)
{
int codigo;
float valor,endivisa;
char cadena[25];
try
{valor=StrToFloat(Edit1->Text);
endivisa=valor/cambio[ComboBox1->ItemIndex];
Label3->Caption =FloatToStr(endivisa)+ " " +ComboBox1->Text;
}
catch(Exception& E)
{
MessageDlg(E.Message, mtError, TMsgDlgButtons() << mbOK, 0);
}
}
//--------------------------------------------------------------------------void __fastcall TForm1::Button2Click(TObject *Sender)
{
Close();
}
//--------------------------------------------------------------------------void __fastcall TForm1::Edit1KeyPress(TObject *Sender, char &Key)
{
if ((Key>='a'&& Key<='z')||(Key>='A'&& Key<='Z'))
{
ShowMessage("Numero Invalido");
Edit1->ReadOnly=true;
}
else
Edit1->ReadOnly=false;
}
//--------------------------------------------------------------------------void __fastcall TForm1::ComboBox1Click(TObject *Sender)
{
Label3->Caption ="Valor del Cambio" ;
}
//----------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//--------------------------------------------------------------------------#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
//--------------------------------------------------------------------------#include <vcl\vcl.h>
#pragma hdrstop
#include "Unit1.h"
//--------------------------------------------------------------------------#pragma resource "*.dfm"
TForm1 *Form1;
//--------------------------------------------------------------------------__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//--------------------------------------------------------------------------void __fastcall TForm1::BitBtn7Click(TObject *Sender)
{
Close();
}
//--------------------------------------------------------------------------void __fastcall TForm1::BitBtn4Click(TObject *Sender)
{
Memo1->Clear();
Memo1->SetFocus();
}
//--------------------------------------------------------------------------void __fastcall TForm1::BitBtn3Click(TObject *Sender)
{
Memo1->CopyToClipboard();
Memo1->SetFocus();
}
//--------------------------------------------------------------------------void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
Memo1->CutToClipboard();
Memo1->SetFocus();
}
Shape1->Left=Shape1->Left+2;
}
//--------------------------------------------------------------------------void __fastcall TForm1::Timer2Timer(TObject *Sender)
{
if (Shape1->Top>=280)
{
contreb++;
Label4->Caption=contreb;
altura=altura*0.70;
Label2->Caption=altura;
Shape1->Top=64*altini/altura;
Shape1->Left= Shape1->Left+1;
if(Shape1->Top>=280)
Shape1->Top=280;
if (altura<=0.5)
{Shape1->Top=280;
Timer2->Enabled =false;
}
}
if (Shape1->Top<280)
{Shape1->Top=Shape1->Top+3;
Shape1->Left=Shape1->Left+1;
}
}
//--------------------------------------------------------------------------void __fastcall TForm1::FormCreate(TObject *Sender)
{
AnsiString cadena = "";
if (InputQuery("Caida libre", "Digite el valor de la altura", cadena))
{altura=StrToInt(cadena);
altini=altura;
Label2->Caption=altura;
Timer1->Enabled=true;}
}
//--------------------------------------------------------------------------void __fastcall TForm1::Timer3Timer(TObject *Sender)
{
StatusBar1->Panels->Items[3]->Text = Now().TimeString();
StatusBar1->Panels->Items[1]->Text = Now().DateString();
}
//---------------------------------------------------------------------------
//--------------------------------------------------------------------------#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
int PosXIni, PosYIni; // Declare at the top of the forms
Word Agno, NMes, Dia, Hora, Min, Seg, MSeg;
bool bandera1=true,bandera2=false,bandera3=false;
//--------------------------------------------------------------------------#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//--------------------------------------------------------------------------__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//--------------------------------------------------------------------------void __fastcall TForm1::FormMouseMove(TObject *Sender, TShiftState Shift,
int X, int Y)
{
if (Shift.Contains(ssLeft))
{StatusBar1->Panels->Items[0]->Text = "X Inicial: " + IntToStr(PosXIni);
StatusBar1->Panels->Items[1]->Text = "Y Inicial: " + IntToStr(PosYIni);
StatusBar1->Panels->Items[2]->Text = "X Final: " + IntToStr(X);
StatusBar1->Panels->Items[3]->Text = "Y Final: " + IntToStr(Y);
}
}
//--------------------------------------------------------------------------void __fastcall TForm1::FormCreate(TObject *Sender)
{
AnsiString mes,dias;
TDateTime actual = Date();
TDateTime DiaSem = Date();
StatusBar1->Panels->Add();
StatusBar1->Panels->Items[0]->Width=80;
StatusBar1->Panels->Items[0]->Text="";
StatusBar1->Panels->Add();
StatusBar1->Panels->Items[1]->Width=80;
StatusBar1->Panels->Items[1]->Bevel=pbRaised;
StatusBar1->Panels->Items[1]->Text="";
StatusBar1->Panels->Add();
StatusBar1->Panels->Items[2]->Width=80;
StatusBar1->Panels->Items[2]->Text="";
StatusBar1->Panels->Add();
StatusBar1->Panels->Items[3]->Width=80;
StatusBar1->Panels->Items[3]->Bevel=pbRaised;
StatusBar1->Panels->Items[3]->Text="";
DecodeDate(actual, Agno, NMes, Dia);
switch(NMes)
{
case 1: mes="Enero";
break;
case 2: mes="Febrero";
break;
case 3: mes="Marzo";
break;
case 4: mes="Abril";
break;
case 5: mes="Mayo";
break;
case 6: mes="Junio";
break;
case 7: mes="Julio";
break;
case 8: mes="Agosto";
break;
case 9: mes="Septiembre";
break;
case 10: mes="Octubre";
break;
case 11: mes="Noviembre";
break;
case 12: mes="Diciembre";
break;
}
switch(DiaSem.DayOfWeek())
{
case 1: mes="Domingo";
break;
case 2: dias="Lunes";
break;
case 3: dias="Martes";
break;
case 4: dias="Miercoles";
break;
case 5: dias="Jueves";
break;
case 6: dias="Viernes";
break;
case 7: dias="Sabado";
break;
}
StatusBar1->Panels->Add();
StatusBar1->Panels->Items[4]->Width=280;
StatusBar1->Panels->Items[4]->Text="Hoy es " + dias+ " " + IntToStr(Dia) + " del Mes " + mes + " del Ao "+ IntToStr(Agno);
StatusBar1->Panels->Add();
StatusBar1->Panels->Items[5]->Width=150;
StatusBar1->Panels->Items[5]->Bevel=pbRaised;
}
//--------------------------------------------------------------------------void __fastcall TForm1::FormMouseDown(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
PosXIni = X;
PosYIni = Y;
}
//--------------------------------------------------------------------------void __fastcall TForm1::FormMouseUp(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
if (RadioButton1->Checked)
Form1->Canvas->Brush->Color = clRed;
if (RadioButton2->Checked)
Form1->Canvas->Brush->Color = clYellow;
if (RadioButton3->Checked)
Form1->Canvas->Brush->Color = clBlue;
if (RadioButton4->Checked)
Form1->Canvas->Brush->Style = bsDiagCross;
if (RadioButton5->Checked)
Form1->Canvas->Brush->Style = bsFDiagonal;
if (RadioButton6->Checked)
Form1->Canvas->Brush->Style = bsCross;
if (bandera1)
{
Form1->Canvas->Rectangle(PosXIni, PosYIni, X, Y);
StatusBar1->Panels->Items[0]->Text = "";
StatusBar1->Panels->Items[1]->Text = "";
StatusBar1->Panels->Items[2]->Text = "";
StatusBar1->Panels->Items[3]->Text = "";
}
if (bandera2)
{
Form1->Canvas->Ellipse(PosXIni, PosYIni, X, Y);
StatusBar1->Panels->Items[0]->Text = "";
StatusBar1->Panels->Items[1]->Text = "";
StatusBar1->Panels->Items[2]->Text = "";
StatusBar1->Panels->Items[3]->Text = "";
}
if (bandera3)
{
Form1->Canvas->MoveTo(PosXIni, PosYIni);
Form1->Canvas->LineTo(X, Y);
StatusBar1->Panels->Items[0]->Text = "";
StatusBar1->Panels->Items[1]->Text = "";
StatusBar1->Panels->Items[2]->Text = "";
StatusBar1->Panels->Items[3]->Text = "";
}
}
//--------------------------------------------------------------------------void __fastcall TForm1::Button1Click(TObject *Sender)
{
Form1->Repaint();
}
//--------------------------------------------------------------------------void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
TDateTime actual = Now();
DecodeTime(actual, Hora, Min, Seg, MSeg);
StatusBar1->Panels->Items[5]->Text="La Hora es " + IntToStr(Hora) + " : "+
IntToStr(Min)+ " : "+IntToStr(Seg);
}
//--------------------------------------------------------------------------void __fastcall TForm1::Button5Click(TObject *Sender)
{
bandera1=true;
bandera2=false;
bandera3=false;
}
//--------------------------------------------------------------------------void __fastcall TForm1::Button3Click(TObject *Sender)
{
bandera1=false;
bandera2=false;
bandera3=true;
}
//--------------------------------------------------------------------------void __fastcall TForm1::Button4Click(TObject *Sender)
{
bandera1=false;
bandera2=true;
bandera3=false;
}
}
//--------------------------------------------------------------------------TALLER DE C++ BUILDER
En la forma 1
5 StaticText
1 Timer
1 BitButton
Modificar las siguientes propiedades en tiempo de diseo
En la forma 2
1 RichEdit
1 BitButton
Modificar las siguientes propiedades en tiempo de diseo
}
delete Buffer; //borra lo que contiene la variable
}
else
ShowMessage("No ha seleccionado link");
}
//---------------------------------------------------------------------------
En este ejemplo se crear un formulario que contendr un componente MediaPlayer que servir para reproducir ficheros .WAV.
Utilizaremos la gestin de excepciones para controlar la correcta ejecucin del programa.
Crear y configurar el proyecto.
En primer lugar, crear el directorio Sonidos. y, si procede, una nueva aplicacin ( File | New Application).
Guardar proyecto: Salvar Unit1.cpp como Ppal.cpp y Project1.bpr como Sonidos.bpr
Configurar el formulario.
Configurar el formulario para que tenga el aspecto mostrado en la figura siguiente:
try {
MediaPlayer1->Open();
MediaPlayer1->Wait = true;
MediaPlayer1->Play();
MediaPlayer1->Close();
}
catch (Exception & e) {
Error (MediaPlayer1->FileName, e);
}
}
//-------------------------------------------------------------void __fastcall TForm1::ErrorBtnClick(TObject *Sender)
{
MediaPlayer1->FileName = "C:\\WINDOWS\\MEDIA\\NoEsta.wav";
try {
MediaPlayer1->Open();
MediaPlayer1->Wait = true;
MediaPlayer1->Play();
MediaPlayer1->Close();
}
catch (Exception & e) {
Error (MediaPlayer1->FileName, e);
}
}
//-------------------------------------------------------------void __fastcall TForm1::OtrosBtnClick(TObject *Sender)
{
OpenDialog1->Title = "Abrir un fichero de sonido";
OpenDialog1->Filter = "Ficheros de sonido (*.wav) | *.WAV";
OpenDialog1->InitialDir = "C:\\WINDOWS";
if (OpenDialog1->Execute())
{
MediaPlayer1->FileName = OpenDialog1->FileName;
try {
MediaPlayer1->Open();
MediaPlayer1->Wait = true;
MediaPlayer1->Play();
MediaPlayer1->Close();
}
catch (Exception & e) {
Error (MediaPlayer1->FileName, e);
}
} // if (OpenDialog1->Execute())
}
//-------------------------------------------------------------void Error (AnsiString & name, Exception & e)
{
ShowMessage ("Fallo en la reproduccin del fichero de sonido: " + name +
"\nExcepcin: " + AnsiString(e.ClassName()) +
"\nDetalles: " + AnsiString(e.Message));
}
//-------------------------------------------------------------Cuando se ejecuta este programa, si se pulsa en el botn Error (se supone que el fichero de sonido que se quiere reproducir no
existe) aparece la siguiente ventana:
En cambio, si se quiere reproducir un fichero cuyo formato no sea .wav aparece la siguiente ventana:
Taller de Rompecabezas
1 Panel, 15 Buttons
object Panel1: TPanel
Left = 72
Top = 24
Width = 185
Height = 185
BorderStyle = bsSingle
object Button2: TButton
Left = 48
Top = 8
Width = 41
Height = 41
Caption = '2'
object Button3: TButton
Left = 88
Top = 8
Width = 41
Height = 41
Caption = '3'
object Button4: TButton
Left = 128
Top = 8
Width = 41
Height = 41
Caption = '4'
object Button5: TButton
Left = 8
Top = 48
Width = 41
Height = 41
Caption = '5'
object Button6: TButton
Left = 48
Top = 48
Width = 41
Height = 41
Caption = '6'
object Button7: TButton
Left = 88
Top = 48
Width = 41
Height = 41
Caption = '7'
object Button8: TButton
Left = 128
Top = 48
Width = 41
Height = 41
Caption = '8'
object Button9: TButton
Left = 8
Top = 88
Width = 41
Height = 41
Caption = '9'
object Button10: TButton
Left = 48
Top = 88
Width = 41
Height = 41
Caption = '10'
object Button11: TButton
Left = 88
Top = 88
Width = 41
Height = 41
Caption = '11'
object Button12: TButton
Left = 128
Top = 88
Width = 41
Height = 41
Caption = '12'
object Button13: TButton
Left = 8
Top = 128
Width = 41
Height = 41
Caption = '13'
object Button14: TButton
Left = 48
Top = 128
Width = 41
Height = 41
Caption = '14'
object Button15: TButton
Left = 88
Top = 128
Width = 41
Height = 41
Caption = '15'
object Button1: TButton
Left = 8
Top = 8
Width = 41
Height = 41
Caption = '1'
//--------------------------------------------------------------------------#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//--------------------------------------------------------------------------#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
int i,j,k;
int m[4][4];
//--------------------------------------------------------------------------__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
{
m[i-1][j]=k;
m[i][j]=0;
Button12->Top=Button12->Top-Button12->Height;
i=j=4;
}
else
if (m[i+1][j]==0&&i<3)
{
m[i+1][j]=k;
m[i][j]=0;
Button12->Top=Button12->Top+Button12->Height;
i=j=4;
}
else
if (m[i][j-1]==0&&j>0)
{
m[i][j-1]=k;
m[i][j]=0;
Button12->Left=Button12->Left-Button12->Width;
i=j=4;
}
else
if (m[i][j+1]==0&&j<3)
{
m[i][j+1]=k;
m[i][j]=0;
Button12->Left=Button12->Left+Button12->Width;
i=j=4;
}
}
}
}
//--------------------------------------------------------------------------void __fastcall TForm1::Button11Click(TObject *Sender)
{
k=StrToInt(Button11->Caption);
for (i=0;i<=3;i++)
for (j=0;j<=3;j++)
{
if (m[i][j]==k)//encuentra el dato
{
if (m[i-1][j]==0&&i>0)
{
m[i-1][j]=k;
m[i][j]=0;
Button11->Top=Button11->Top-Button11->Height;
i=j=4;
}
else
if (m[i+1][j]==0&&i<3)
{
m[i+1][j]=k;
m[i][j]=0;
Button11->Top=Button11->Top+Button11->Height;
i=j=4;
}
else
if (m[i][j-1]==0&&j>0)
{
m[i][j-1]=k;
m[i][j]=0;
Button11->Left=Button11->Left-Button11->Width;
i=j=4;
}
else
if (m[i][j+1]==0&&j<3)
{
m[i][j+1]=k;
m[i][j]=0;
Button11->Left=Button11->Left+Button11->Width;
i=j=4;
}
}
}
}
//--------------------------------------------------------------------------void __fastcall TForm1::Button14Click(TObject *Sender)
{
k=StrToInt(Button14->Caption);
for (i=0;i<=3;i++)
for (j=0;j<=3;j++)
{
if (m[i][j]==k)//encuentra el dato
{
if (m[i-1][j]==0&&i>0)
{
m[i-1][j]=k;
m[i][j]=0;
Button14->Top=Button14->Top-Button14->Height;
i=j=4;
}
else
if (m[i+1][j]==0&&i<3)
{
m[i+1][j]=k;
m[i][j]=0;
Button14->Top=Button14->Top+Button14->Height;
i=j=4;
}
else
if (m[i][j-1]==0&&j>0)
{
m[i][j-1]=k;
m[i][j]=0;
Button14->Left=Button14->Left-Button14->Width;
i=j=4;
}
else
if (m[i][j+1]==0&&j<3)
{
m[i][j+1]=k;
m[i][j]=0;
Button14->Left=Button14->Left+Button14->Width;
i=j=4;
}
}
}
}
//---------------------------------------------------------------------------