Yil2201
Messages postés134Date d'inscriptionmercredi 1 décembre 2004StatutMembreDernière intervention10 août 2008
-
15 oct. 2005 à 09:44
ni69
Messages postés1418Date d'inscriptionsamedi 12 juin 2004StatutMembreDernière intervention 5 juillet 2010
-
15 oct. 2005 à 16:32
Salut! Ben voila je sais que le problème a déja été posé mais aucune des réponses ne me satisfaity alors je vous le demande. Voila, je voudrais savoir comment faire pour que lorsqu'on appuye sur une touche ( ici ce sera fleche droite ), le programme joue l'evenement OnClick d'un label ... ou un bouton.
ni69
Messages postés1418Date d'inscriptionsamedi 12 juin 2004StatutMembreDernière intervention 5 juillet 201012 15 oct. 2005 à 16:32
Je t'ai refait l'intégralité de ton code afin qu'il soit plus "propre" et plus court :
J'ai vérifié, il marche ! Il ne reste plus qu'à rajouter ton bouton de fermeture du programme...
Modifications notables : plus de timers, une seule procédure assure le déplacement de l'image. Un Case...Of remplace les nombreux if que
tu utilisais pour le lancement des programmes. Les applications et la
position de l'image correspondante sont stockées dans un tableau. On ne
teste pas chaque cas séparément, tout est géré dans des boucles de test.
Le code n'est pas vraiment commenté (je l'ai fait rapidement). Si tu as des questions n'hésite pas ! Je pense qu'il y a encore possibilité d'optimiser...
Le code suivant n'utilise qu'une image et qu'un label nommés respectivement Image1 et Label1.
procedure FormKeyPress(Sender: TObject; var Key: Char);
procedure MoveImageTo(App : string);
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;
var
Form1: TForm1;
Applications : array [0..4] of array [0..1] of String;
IsAlreadyMoving : boolean= false;
implementation
{$R *.dfm}
// Initialisation de la Form
procedure TForm1.FormCreate(Sender: TObject);
begin
Applications[0,0] : = 'MSN Messenger'; // Nom de l'application
Applications[0,1] := '104';
//
Position de l'image sur la fiche
Applications[1,0] := 'Internet Explorer';
Applications[1,1] := '224';
Applications[2,0] := 'Lecteur Windows Media';
Applications[2,1] := '344';
Applications[3,0] := 'Outlook Express';
Applications[3,1] := '464';
Applications[4,0] := 'Mozilla FireFox';
Applications[4,1] := '584';
DoubleBuffered := true;
Label1.Caption := 'MSN Messenger'; // Réglages par défaut
Image1.Left := 104;
end ;
// Gestion de l'appui sur touches
procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
var
i,SelectedApp : byte;
begin
// Drapeau pour éviter les erreurs d'affichage
if IsAlreadyMoving then exit;
IsAlreadyMoving : = true;
if key= '6' then begin // Application suivante... [touche6]
for i: =0 to Length(Applications)-1 do begin
if Applications[i,0] = Label1.Caption then begin
if i = Length(Applications)-1 then SelectedApp := 0 else
SelectedApp : = i+1;
Label1.Caption := Applications[SelectedApp,0];
break;
end ;
end;
// Déplacement de ton image
MoveImageTo(Label1.Caption);
end else if key ='4' then begin// Application précédente... [touche4]
for i:= 0 to Length(Applications)-1 do begin
if Applications[i,0] = Label1.Caption then begin
if i 0 then SelectedApp : Length(Applications)-1 else
SelectedApp := i-1;
Label1.Caption := Applications[SelectedApp,0];
break;
end ;
end;
// Déplacement de ton image
MoveImageTo(Label1.Caption);
end else if key ='5' then begin // Module de Lancement d'Applications [touche5]
case Image1.Left of
584: if FileExists('C:/Program Files/Mozilla Firefox/firefox.exe') then ShellExecute(0,'OPEN','C:/Program Files/Mozilla Firefox/firefox.exe', Nil, Nil, SW_SHOW) else ShowMessage('Firefox ne semble pas installé sur votre ordinateur, veuillez vérfifier les options');
Yil2201
Messages postés134Date d'inscriptionmercredi 1 décembre 2004StatutMembreDernière intervention10 août 2008 15 oct. 2005 à 12:17
Merci beaucoup! Quel est "le code" de la touche droite et gauhe ? ( par ex : 8 c'est '8' ) ??
Et comment faire pour qu'une procedure execute la procedure Onclick d'un autre composant ?
Yil2201
Messages postés134Date d'inscriptionmercredi 1 décembre 2004StatutMembreDernière intervention10 août 2008 15 oct. 2005 à 13:14
Salut, concernant le OnClick(Button1) ca marche pas. Ca compile mùets lorsque j'appuye sur la touche il y a une erreur EAVolationAccess a l'adresse 000000000 ... que faire ?
ni69
Messages postés1418Date d'inscriptionsamedi 12 juin 2004StatutMembreDernière intervention 5 juillet 201012 15 oct. 2005 à 13:49
Cherche "codes touche virtuelle" dans l'aide de delphi pour avoir les
correspondances des touches du clavier utilisables dans les événements
OnKeyDown et OnKeyPress.
Peux-tu également me donnet le code de ces événements ?
ni69
Messages postés1418Date d'inscriptionsamedi 12 juin 2004StatutMembreDernière intervention 5 juillet 201012 15 oct. 2005 à 13:54
Justement, si tu exécutes le programme dans l'environnement de Delphi
(touche F9 - Run), sur quelle ligne s'arrête le programme ?
Donnes-moi le code complet, ce sera plus simple...
Yil2201
Messages postés134Date d'inscriptionmercredi 1 décembre 2004StatutMembreDernière intervention10 août 2008 15 oct. 2005 à 13:55
procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
if key='6' then
if label1.Caption = 'MSN Messenger' then
begin
msnie.Enabled:=True;
Label1.Caption:='Internet Explorer';
end
else
if Label1.Caption = 'Outlook Express' then
begin
oefire.Enabled:=True;
Label1.Caption:='Mozilla FireFox';
Label2.Caption:='Mozilla Foundation';
end
else
if Label1.Caption = 'Lecteur Windows Media' then
begin
wmpoe.Enabled:=True;
Label1.Caption:='Outlook Express';
end
else
if label1.Caption = 'Internet Explorer' then
begin
iewmp.Enabled:=True;
Label1.Caption:='Lecteur Windows Media';
end;
if key='4' then
if Label1.Caption = 'Internet Explorer' then
begin
iemsn.Enabled:=True;
label1.Caption:='MSN Messenger';
end
else
if label1.Caption = 'Mozilla FireFox' then
begin
fireoe.Enabled:=True;
Label1.Caption:='Outlook Express';
label2.Caption:='Microsoft Corporation';
end
else
if Label1.Caption = 'Outlook Express'
then
begin
oewmp.Enabled:=True;
Label1.Caption:='Lecteur Windows Media';
end
else
if Label1.Caption = 'Lecteur Windows Media' then
begin
wmpie.Enabled:=True;
Label1.Caption:='Internet Explorer';
Label2.Caption:='Microsoft Corporation';
end;
if key='5' then
begin
if Image1.Left = 584 then
begin
if FileExists('C:/Program Files/Mozilla Firefox/firefox.exe') then ShellExecute(0,'OPEN','msimn.exe', Nil, Nil, SW_SHOW) else ShowMessage('Firefox ne semble pas installé sur votre ordinateur, veuillez vérfifier les options')
end;
if Image1.Left = 464 then
begin
ShellExecute(0,'OPEN','msimn.exe', Nil, Nil, SW_SHOW);
end;
if Image1.Left = 344 then
begin
ShellExecute(0,'OPEN','wmplayer.exe', Nil, Nil, SW_SHOW);
end;
if Image1.Left = 224 then
begin
ShellExecute(0,'OPEN','iexplore.exe', Nil, Nil, SW_SHOW);
end;
if Image1.Left = 104 then ShellExecute(0,'OPEN','msnmsgr.exe', Nil, Nil, SW_SHOW);
end;
procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
Application.Terminate;
end;
procedure TForm1.Label3Click(Sender: TObject);
begin
if Image1.Left = 584 then
begin
if FileExists('C:/Program Files/Mozilla Firefox/firefox.exe') then ShellExecute(0,'OPEN','msimn.exe', Nil, Nil, SW_SHOW) else ShowMessage('Firefox ne semble pas installé sur votre ordinateur, veuillez vérfifier les options')
end;
if Image1.Left = 464 then
begin
ShellExecute(0,'OPEN','msimn.exe', Nil, Nil, SW_SHOW);
end;
if Image1.Left = 344 then
begin
ShellExecute(0,'OPEN','wmplayer.exe', Nil, Nil, SW_SHOW);
end;
if Image1.Left = 224 then
begin
ShellExecute(0,'OPEN','iexplore.exe', Nil, Nil, SW_SHOW);
end;
if Image1.Left = 104 then ShellExecute(0,'OPEN','msnmsgr.exe', Nil, Nil, SW_SHOW);
end;
procedure TForm1.Label4Click(Sender: TObject);
begin
if Label1.Caption = 'Internet Explorer' then
begin
iemsn.Enabled:=True;
label1.Caption:='MSN Messenger';
end
else
if label1.Caption = 'Mozilla FireFox' then
begin
fireoe.Enabled:=True;
Label1.Caption:='Outlook Express';
label2.Caption:='Microsoft Corporation';
end
else
if Label1.Caption = 'Outlook Express'
then
begin
oewmp.Enabled:=True;
Label1.Caption:='Lecteur Windows Media';
end
else
if Label1.Caption = 'Lecteur Windows Media' then
begin
wmpie.Enabled:=True;
Label1.Caption:='Internet Explorer';
Label2.Caption:='Microsoft Corporation';
end;
end;
procedure TForm1.wmpieTimer(Sender: TObject);
begin
Image1.Left:=Image1.Left - 5;
if Image1.Left = 224 then wmpie.Enabled:=False;
end;
procedure TForm1.Label5Click(Sender: TObject);
begin
if label1.Caption = 'MSN Messenger' then
begin
msnie.Enabled:=True;
Label1.Caption:='Internet Explorer';
end
else
if Label1.Caption = 'Outlook Express' then
begin
oefire.Enabled:=True;
Label1.Caption:='Mozilla FireFox';
Label2.Caption:='Mozilla Foundation';
end
else
if Label1.Caption = 'Lecteur Windows Media' then
begin
wmpoe.Enabled:=True;
Label1.Caption:='Outlook Express';
end
else
if label1.Caption = 'Internet Explorer' then
begin
iewmp.Enabled:=True;
Label1.Caption:='Lecteur Windows Media';
end;
end;
procedure TForm1.iewmpTimer(Sender: TObject);
begin
Image1.Left:=Image1.Left + 5;
if Image1.Left = 344 then iewmp.Enabled:=False;
end;
procedure TForm1.wmpoeTimer(Sender: TObject);
begin
Image1.Left:=Image1.Left + 5;
if Image1.Left = 464 then wmpoe.Enabled:=False;
end;
procedure TForm1.oewmpTimer(Sender: TObject);
begin
Image1.Left:=Image1.Left - 5;
if Image1.Left = 344 then oewmp.Enabled:=False;
end;
procedure TForm1.SpeedButton2Click(Sender: TObject);
begin
ShowMessage('xLauncher' + #13 + 'Version 1.0' + #13 + 'Build: OE-WMP-IE-FIRE-MSN' + #13 + 'Créé par Yil2201' + #13 + 'Tous droits réservés, la copie est interdite.');
end;
procedure TForm1.oefireTimer(Sender: TObject);
begin
Image1.Left:=Image1.Left + 5;
if Image1.Left = 584 then oefire.Enabled:=False;
end;
procedure TForm1.fireoeTimer(Sender: TObject);
begin
Image1.Left:=Image1.Left - 5;
if Image1.Left = 464 then fireoe.Enabled:=False;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Form1.DoubleBuffered:=True;
end;
procedure TForm1.iemsnTimer(Sender: TObject);
begin
Image1.Left:=Image1.Left - 5;
if Image1.Left = 104 then iemsn.Enabled:=False;
end;
procedure TForm1.msnieTimer(Sender: TObject);
begin
Image1.Left:=Image1.Left + 5;
if Image1.Left = 224 then msnie.Enabled:=False;
end;
procedure TForm1.Label6Click(Sender: TObject);
begin
ShowMessage('Les options seront présentes dans le Build7000.');
end;
procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
if key='6' then
if label1.Caption = 'MSN Messenger' then
begin
msnie.Enabled:=True;
Label1.Caption:='Internet Explorer';
end
else
if Label1.Caption = 'Outlook Express' then
begin
oefire.Enabled:=True;
Label1.Caption:='Mozilla FireFox';
Label2.Caption:='Mozilla Foundation';
end
else
if Label1.Caption = 'Lecteur Windows Media' then
begin
wmpoe.Enabled:=True;
Label1.Caption:='Outlook Express';
end
else
if label1.Caption = 'Internet Explorer' then
begin
iewmp.Enabled:=True;
Label1.Caption:='Lecteur Windows Media';
end;
if key='4' then
if Label1.Caption = 'Internet Explorer' then
begin
iemsn.Enabled:=True;
label1.Caption:='MSN Messenger';
end
else
if label1.Caption = 'Mozilla FireFox' then
begin
fireoe.Enabled:=True;
Label1.Caption:='Outlook Express';
label2.Caption:='Microsoft Corporation';
end
else
if Label1.Caption = 'Outlook Express'
then
begin
oewmp.Enabled:=True;
Label1.Caption:='Lecteur Windows Media';
end
else
if Label1.Caption = 'Lecteur Windows Media' then
begin
wmpie.Enabled:=True;
Label1.Caption:='Internet Explorer';
Label2.Caption:='Microsoft Corporation';
end;
if key='5' then
begin
if Image1.Left = 584 then
begin
if FileExists('C:/Program Files/Mozilla Firefox/firefox.exe') then ShellExecute(0,'OPEN','msimn.exe', Nil, Nil, SW_SHOW) else ShowMessage('Firefox ne semble pas installé sur votre ordinateur, veuillez vérfifier les options')
end;
if Image1.Left = 464 then
begin
ShellExecute(0,'OPEN','msimn.exe', Nil, Nil, SW_SHOW);
end;
if Image1.Left = 344 then
begin
ShellExecute(0,'OPEN','wmplayer.exe', Nil, Nil, SW_SHOW);
end;
if Image1.Left = 224 then
begin
ShellExecute(0,'OPEN','iexplore.exe', Nil, Nil, SW_SHOW);
end;
if Image1.Left = 104 then ShellExecute(0,'OPEN','msnmsgr.exe', Nil, Nil, SW_SHOW);
end;
end;
procedure TForm1.Label7Click(Sender: TObject);
begin
ShowMessage('5 : Lancer le programme, 4 : Précédent : Gauche, 6 : Suivant : Droite');
end;