¿Quieres programar un despertador usando Delphi?
Cree un nuevo programa y agregue los siguientes componentes al formulario:
Temporizador1: TTimer;
Imagen1: TImage;//esfera del reloj
Edit1: TEdit; //Cuadro de fecha
Etiqueta1: TLabel;
PopupMenu1: TPopupMenu;
Luego en {$R *.DFM} Agregar la siguiente oración {$R CLOCKSOU.RES} <--archivo de sonido del reloj,
(Nota: CLOCKSOU.RES debe crear primero un nuevo archivo usando el Bloc de notas de Windows y agregar las siguientes líneas p>
CLICKBEL WAVE "CLICKBEL.WAV"
TIMEBELL WAVE "TIMEBELL.WAV"
Guárdelo como archivo CLOCKSOU.RC y luego use BRCC32.exe en la solución DOS para compilar CLOCKSOU. RC
en el archivo de recursos CLOCOSOU.RES en formato DELPHI. Por supuesto, si los pasos le resultan demasiado complicados, la forma más sencilla es descargar el archivo completo desde mi página de inicio
Programa. code)
OK, después de completar los pasos anteriores, podemos ingresar el siguiente código en el cuadro de código del formulario.
unidad Unidad1;
interfaz
usa
Windows, Mensajes, SysUtils, Clases, Gráficos, Controles, Formularios, Diálogos,
ExtCtrls,unidad2, StdCtrls,inifiles,MMSystem, Menús;
tipo
TForm1 = clase(TForm)
Temporizador1: TTimer;
Imagen1: TImage;
Editar1: TEdit;
Etiqueta1: TLabel;
PopupMenu1: TPopupMenu;
pop1: TMenuItem;
pop2: TMenuItem;
pop4: TMenuItem;
pop3: TMenuItem;
pop5: TMenuItem;
N1: TMenuItem;
procedimiento Timer1Timer(Remitente: TObject);
procedimiento timdrow(tim:real;long,col:integer);
procedimiento FormCreate(Remitente: TObject);
procedimiento Image1Click(Remitente: TObject);
procedimiento pop1Click(Remitente: TObject);
procedimiento pop2Click (Remitente: TObject);
procedimiento pop4Click(Remitente: TObject);
procedimiento pop5Click(Remitente: TObject);
procedimiento pop3Click(Remitente: TObject) ;
procedimiento tiniwr();
procedimiento FormClose(Remitente: TObject; var Acción: TCloseAction);
procedimiento N1Click(Remitente: TObject); p> p>
privado
{ Declaraciones privadas }
público
{ Declaraciones públicas }
fin;
var
Form1: TForm1;
CLOCKBELL,wid,pofse:integer;
tim1,tim2,tim3,tim4:real; p>
dtme: TDateTime;
timini:tinifile;
dtim,textdef,tmfilename:string;
implementación
{$ R *.DFM}
{$R LL1.RES} //Archivo de sonido del reloj
procedimiento tform1.tiniwr();
comenzar
timini:=TIniFile.Create(tmfilename);
con timini do
comenzar
WriteString('content','text',textdef);
Writestring('parameter','time',dtim);
WriteBool(' Parámetro','Timbre de tiempo permitido',pop1.checked);
WriteBool('Parámetro','Segundo timbre permitido',pop2.checked);
WriteBool('Parámetro' , 'Tiempo permitido',pop3.checked);
end;
timini.free;
end;
procedimiento tform1. timdrow (tim:real;long,col:integer); //Función de proceso de puntero.
var
xx,yy:integer;
vtt,vt:real;
comenzar
SI (TIM2=59) Y (TIM3=0) ENTONCES TIM:=TIM-1;
SI (COL=3)o (col=6) ENTONCES
si col=3 luego VT:=TIM1*5+(TIM2/720)
si no comenzar
VT:=TIM1*5+((TIM2-1)/720);
col:=5;
fin
ELSE vt:=tim;
vt:=Pi-pi*vt/30-2*pi *(vt-15); //Obtiene la coordenada Y del final del puntero
vtt:=int(long*sin(vt))+45 //Obtiene la coordenada X del final; del puntero
xx:=strtoint(floattostr(vtt));
vtt:=int(long*cos(vt))+45;
yy:=strtoint(floattostr (vtt));
case col of //Juzga si el puntero a dibujar es el minutero, el segundero o el horario
0:begin
imagen1.Canvas.pen .Color:=clgray
imagen1.Canvas.pen.Width:=1
END;
1:COMENZAR
imagen1.Canvas.pen.Color:=clRed;
image1.Canvas.pen.Width:=1;
FIN;
2:COMENZAR p>
imagen1.Canvas.pen.color:=clblue;
imagen1.Canvas.pen.Width:=2;
FIN;
3:COMIENZO
imagen1.canvas.pen.color:=clgreen;
imagen1.Canvas.pen.Width:=2 ;
FIN;
p>4:comenzar
imagen1.canvas.pen.color:=clblack;
imagen1.Canvas .pen.Width:=1;
END;
5:begin
imagen1.canvas.pen.color:=clgray;
image1.Canvas.pen.Width:=3;
END;
end;
IMAGE1.Canvas.Ellipse(43,43,47, 47);
image1.Canvas. MoveTo(45,45);
image1.Canvas.Lineto(xx,yy);
end; p>
procedimiento TForm1.Timer1Timer(Sender: TObject) ;
var
str1,str2:string;
comenzar
str1:=timetostr(time());
STR2:=COPY(STR1,2,1);
si str
2=':' then pofse:=0 else pofse:=1;
EDIT1.TEXT:=' '+DATETOSTR(DATE()); //Fecha de datos en el disco de fecha
str2:=copy(str1,pofse+6,2);
tim4:=strtofloat(str2);
if tim4<>tim3 entonces //Juzga si ha llegado Es hora de mover el puntero
comenzar
si (tim3=0) o (tim3=15) o (tim3=30)
o (tim3 =45) luego timdrow(tim3,39,4) else timdrow(tim3,39,0);
tim3:=tim4;
si pop2.marcado entonces PlaySound(PChar( 'CLICKBEL' ),
hInstance, snd_ASync o snd_Resource); //El sonido del "tick" del segundero
str2:=copy(str1,1,pofse+1) ;
IF(TIM3=0)AND(TIM2=59)THEN //Determina si es hora de emitir la "campana" horaria
COMENZAR
CLOCKBELL:=STRTOINT( STR2);
SI CLOCKBELL=0 ENTONCES CLOCKBELL:=12;
FIN;
SI CLOCKBELL>12 ENTONCES CLOCKBELL:=CLOCKBELL -12;
p>
timdrow(tim1,26,6);
tim1:=strtofloat(str2);
timdrow(tim2, 33,5);
str2:=copiar(str1,pofse+3,2);
tim2:=strtofloat(str2);
timdrow( tim2,33,2);
SI (TIM2<>59) Y (TIM4<>0) ENTONCES timdrow(tim1-1,26,3) ELSE TIMDROW(TIM1,26,3);
tim2:=strtofloat (str2);
str2:=copiar(str1,pofse+3,2);
timdrow(tim3,39,1) ;
SI CLOCKBELL >=1 ENTONCES
COMENZAR
SI (CLOCKBELL<>0)y(pop2.checked) ENTONCES
PlaySound(PChar('TIMEBELL'), hInstance ,
snd_ASync o snd_Resource);// Suena el "timbre" del reloj cada hora
DEC(CLOCKBELL);
FIN;
if (pop3.checked)y(strtotime(dtim)<=time()) entonces//Determina si ha llegado la hora programada
comenzar p>
form2.Button2.Caption:='Cancel';
clockbell:=120;
form2.Show; //Muestra el mensaje a ti mismo.
end;
END;
end;
procedimiento TForm1.FormCreate(Remitente: TObject); //El programa de lectura inicia la Inicialización); settings
var
str1,str2:string;
begin
tmfilename:=ExtractFilePath(Application.EXEName)+ 'clock1. ini';
timini:=TIniFile.Create(tmfilename);
con timini haz
comenzar
Textdef: =readString( 'Contenido','Texto','Ingrese aquí su recordatorio');
dtim:=readstring('Parameter','Time','23:59:59' );
pop1.checked:=readBool('Parámetro','Alarma de tiempo permitida',true);
pop2.checked:=readBool('Parámetro','Segunda alarma permitida' ',true );
pop3.checked:=readBool('Parámetro','Tiempo permitido',false);
form1.Left:=readinteger('Posición',' Coordenada X' ,566);
form1.top:=readinteger('posición','coordenada Y',8);
end;
timini .free;
dtme:=time();
pop2.checked:=true;
pop1.Checked:=true;
str1 :=timetostr(time());
STR2:=COPY(STR1,2,1);
Si str2=':' entonces pofse:=0 else pofse:= 1;
imagen1.Canvas.BRUSH.COLOR:=CLBLACK;;
str2:=copiar(str1,pofse+6,2);
tim3 :=strtofloat(str2);
str2:=copiar(str1,pofse+3,2);
tim2:=strtofloat(str2);
str2:=copiar(str1,1,pofse+1);
tim1:=strtofloat(str2);
CLOCKBELL:=-1;
fin ;
procedimiento TForm1.Image1Click(Sender: TObject);//Manejo del clic del mouse de marcación
comenzar
PopupMenu1.Popup(FORM1 .LEFT+40, FORM1.TOP+150);
fin;
procedimiento TForm1.pop1Click(Remitente: TObject);
comenzar
si pop1 .marcado y luego pop1.checked:=false else pop1.checked:=true;
form1.tiniwr();
end;
procedimiento TForm1.pop2Click (Remitente: TObject);
comenzar
<p>si pop2.checked entonces pop2.checked:=false else pop2.checked:=true;
form1.tiniwr();
end;
procedimiento TForm1.pop4Click(Remitente: TObject);
comenzar
form2.show;
form1.tiniwr();
finalizar ;
procedimiento TForm1.pop5Click(Remitente: TObject);
comenzar
cerrar;
finalizar;
procedimiento TForm1.pop3Click(Remitente: TObject);
comenzar
si pop3.Checked entonces
comenzar
pop3.Checked: =false;
form2.Button2.Caption:='Cancelar';
finalizar
más
comenzar
pop3.Checked:=true;
form2.Button2.Caption:='Cerrar';
fin;
form1.tiniwr();
fin;
procedimiento TForm1.FormClose(Remitente: TObject; var Acción: TCloseAction);
comenzar
timini:=TIniFile. Create('tmfilename');
con timini do
comenzar
Writeinteger('posición','coordenada X',form1.Left);// Guarde la coordenada X inicial de la ventana del reloj
Writeinteger('position','Y coordina',form1.top);//Guarde la coordenada Y inicial de la ventana del reloj
fin; p>
timini.free;
fin;
procedimiento TForm1.N1Click(Remitente: TObject);
comenzar
showmessage('Despertador analógico 0.1,'+#13+' Copia(R)ight por Suye.2001');
end;
end. p>