Ce programme permet de créer deux Sous processus differents;"addition" & "soustraction" entre deux nombres que vous désigne.
p.s: désolais; j'ai mis les commentaires en anglais.
Source / Exemple :
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Ichi.h"
#include "Ni.h"
//---------------------------------------------------------------------------
#include "MyProject1.h"
#include "MyProject2.h"
#include "MyProject3.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm2 *Form2;
Thread1 *leftTHR;
Thread2 *rightTHR;
//---------------------------------------------------------------------------
int StopedR=0,StopedL=0,do_it_again=0;
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
: TForm(Owner)
{
Label5->Caption="Addition";
Label6->Caption="Subtraction";
}
//---------------------------------------------------------------------------
void __fastcall TForm2::Button1Click(TObject *Sender)
{
Form2->Hide();
Form3->Show();
}
//---------------------------------------------------------------------------
//int p;
void __fastcall TForm2::Timer1Timer(TObject *Sender)
{
Label2->Caption="This programme couldn't work ";
Label3->Caption="both in a MONO-CPU computer ";
Label4->Caption="or in more than two CPU-computer!";
/*p++;
Form2->ClientHeight=10*p;
Form2->ClientWidth=10*p;
if((Form2->ClientWidth==5)&&(Form2->ClientHeight==5))
Timer1->Enabled=false;*/
}
//---------------------------------------------------------------------------
void __fastcall TForm2::Button2Click(TObject *Sender)
{
if((Form2->Edit1->Text==1)&&(Form2->Edit2->Text==1)&&(do_it_again==0))
{
MessageBox(NULL,"You Didn't Give Any Number!",NULL, MB_OK|MB_ICONSTOP);
ShowMessage("Anyway the '1' will be the default number.");
do_it_again=1;
}
leftTHR = new Thread1(false);
rightTHR = new Thread2(false);
// To Resume the two threads from the begining
// we should write:
// leftTHR = new Thread1(true);
// rightTHR = new Thread2(true);
}
//---------------------------------------------------------------------------
void __fastcall TForm2::N1Click(TObject *Sender)
{
Form3->Show();
Form2->Hide();
}
//---------------------------------------------------------------------------
void __fastcall TForm2::Button4Click(TObject *Sender)
{
if(StopedR==0)
{
rightTHR->Suspend();//Thread is stoped now.
Button4->Caption="Resume";
StopedR=1;
}
else
{
rightTHR->Resume();
Button4->Caption="Suspend";
//Resume means run again the thread after Suspension.
StopedR=0;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm2::Button3Click(TObject *Sender)
{
if(StopedL==0)
{
leftTHR->Suspend();//Thread is stoped now.
Button3->Caption="Resume";
StopedL=1;
}
else
{
leftTHR->Resume();
Button3->Caption="Suspend";
//Resume means run again the thread after Suspension.
StopedL=0;
}
}
//---------------------------------------------------------------------------
Conclusion :
Voilà C mon premier Project Ici, si vous avez des quetions ou des commantaires..je suis là.
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.