|
发表于 2020-7-28 23:30:01
|
显示全部楼层
我试了一下,可以的,下面是主要代码:
//------------------------------子窗体代码------------------------------
class TMDIChild : public TForm
{
__published:
TMemo *Memo1;
void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
void __fastcall FormCreate(TObject *Sender);
void __fastcall FormDestroy(TObject *Sender);
private:
mtimer *mt;
public:
virtual __fastcall TMDIChild(TComponent *Owner);
};
void __fastcall TMDIChild::FormCreate(TObject *Sender)
{
mt=new mtimer(this);
}
void __fastcall TMDIChild::FormDestroy(TObject *Sender)
{
delete mt;
}
//----------------------线程代码---------------------------------------------------
class mtimer : public TThread
{
private:
TForm *_fm;
void __fastcall UpdateCaption();
protected:
void __fastcall Execute();
public:
__fastcall mtimer(TForm *);
};
__fastcall mtimer::mtimer(TForm *fm)
: TThread(false),_fm(fm)
{
}
//---------------------------------------------------------------------------
void __fastcall mtimer::Execute()
{
//---- Place thread code here ----
while(!this->Terminated)
{
Synchronize(&UpdateCaption);
Sleep(200);
}
}
//---------------------------------------------------------------------------
void __fastcall mtimer::UpdateCaption()
{
_fm->Caption = Now();
}
|
|