13,873
社区成员
发帖
与我相关
我的任务
分享
//unit.h
//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
void __fastcall FormCreate(TObject *Sender);
private: // User declarations
void __fastcall WndProc(Messages::TMessage &Message);
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
class work : public TThread
{
private:
protected:
void __fastcall Execute();
public:
__fastcall work(bool CreateSuspended);
HWND mainWin;
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
//unit.cpp
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
work *wth;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
__fastcall work::work(bool CreateSuspended)
: TThread(CreateSuspended)
{
FreeOnTerminate=true;
}
//---------------------------------------------------------------------------
void __fastcall work::Execute()
{
while(true)
{
Sleep(2000);
Beep(1000,100);
PostMessage(mainWin,WM_USER+10,0,0);
break;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
wth=new work(true);
wth->mainWin=Handle;
wth->Resume();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::WndProc(Messages::TMessage &Message)
{
if(Message.Msg==WM_USER+10)
{
ShowMessage("th exit");
return;
}
TForm::WndProc(Message);
}
//---------------------------------------------------------------------------
TMyThread *Thread=new TMyThread(false);
Thread->WaitFor();
Sleep(500);
Thread->Terminate();
delete Thread;