线程函数和创建线程
刚学这个 不懂额。然后看书自己写 有些地方错误的。
DWORD WINAPI ThreadFunc(LPVOID lpParameter)
{
for(int i=1;i<=100000;i++)
{
Form1->label1->Caption = i;
}
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
int hHandle;
DWORD threadID;
hHandle = (int)CreateThread(NULL, 0, ThreadFunc, (void*)this, 0, &threadID);
if(hHandle == 0)
{
MessageBox(Handle, "没有线程", NULL, MB_OK);
}
}
class EnThread : public TThread
{
private:
string iFile,oFile;
TAes* _aes;
bool Encrypt;
protected:
void __fastcall Execute();
public:
__fastcall EnThread(TAes* aes,const string& in,const string& out,bool En,bool CreateSuspended=true)
: TThread(CreateSuspended)
{
iFile=in;
oFile=out;
_aes=aes;
Encrypt=En;
}
};
void __fastcall TForm1::ButtonEnClick(TObject *Sender)
{
this->SetKey();
TAes* aes = new TAes(this->keysize,this->key);
this->InfoAes = aes;
EnThread* En= new EnThread(aes,this->InFileStr,this->OutFileStr,this->Encry,true);
this->Timer1->Enabled =true;
this->stime =Time();
En->Resume();
this->PageControl->Enabled =false;
this->ClientHeight =226;
this->SetFormMy();
}