哪位给几个createevent,openevent,setevent的例子?

faiqi 2003-10-16 04:12:16
最好都用到这几个函数,因为这几个函数的用法我  看过了,但没有例子,很是不解,所以哪位能给个例子吗?谢谢!
...全文
656 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
swordwins 2003-12-28
  • 打赏
  • 举报
回复
接收到信号后干什么呢,不懂望赐教
nightfallrove 2003-12-28
  • 打赏
  • 举报
回复
我用EVENT时都直接用SDK,
CreateEvent()
setEvent()
看看MSDN就会用了,,
faiqi 2003-10-17
  • 打赏
  • 举报
回复
tigerhohoo,非常感谢你!
yjy1001 2003-10-16
  • 打赏
  • 举报
回复
写得好tigerhohoo(老虎不吃人) ( )
tigerhohoo 2003-10-16
  • 打赏
  • 举报
回复
//---------------------------------------------------------------------------
#include <vcl\vcl.h>
#pragma hdrstop

#include "thread5main.h"
//---------------------------------------------------------------------------
#pragma resource "*.dfm"
TForm1 *Form1;

//Global variables
int Count;
HANDLE hCountUp, hCountDown;

//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
//Clear the memo box
mMessage->Lines->Clear();
//Set count to zero
Count = 0;
//Create the count up event as auto-reset and signalled
hCountUp = CreateEvent(NULL, FALSE, TRUE, NULL);
//Create the count down event as auto-reset and un-signalled
hCountDown = CreateEvent(NULL, FALSE, FALSE, NULL);
//Create the thread to count up
UpThread = new TCounterThread(TRUE);
//Create the thread to count down
DownThread = new TCounterThread(FALSE);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormDestroy(TObject *Sender)
{
//Terminate the count up thread
UpThread->Terminate();
//Terminate the count down thread
DownThread->Terminate();
//Close the count up event
CloseHandle(hCountUp);
//Close the count down event
CloseHandle(hCountDown);
}
//---------------------------------------------------------------------------
__fastcall TCounterThread::TCounterThread(bool TheCountUp) : TThread(TRUE)
{
//Tell the object to free itself once it is terminated
FreeOnTerminate = TRUE;
//Remember whether we are counting up or down
CountUp = TheCountUp;
//Resume execution of the thread
Resume();
}
//---------------------------------------------------------------------------
void __fastcall TCounterThread::Execute(void)
{
//As long as the thread is not terminated
while (!Terminated)
{
//If this is the count up thread
if (CountUp)
//Wait for the count up event to be raised
WaitForSingleObject(hCountUp, INFINITE);
//Otherwise, this is the count down thread
else
//Wait for the count down event to be raised
WaitForSingleObject(hCountDown, INFINITE);

//If this is the count up thread
if (CountUp)
{
//Add 10 to count
Count += 10;
//Wait 1000 milliseconds
Sleep(1000);
//Update the screen
Synchronize(UpdateDisplay);
//Raise the count down event
SetEvent(hCountDown);
}
//Otherwise, this is the count down thread
else
{
//Subtract 10 from count
Count -= 10;
//Wait 1000 milliseconds
Sleep(1000);
//Update the display
Synchronize(UpdateDisplay);
//Raise the count up event
SetEvent(hCountUp);
}
}
}
//---------------------------------------------------------------------------
void __fastcall TCounterThread::UpdateDisplay(void)
{
//If there are too many memo lines, clear it
if (Form1->mMessage->Lines->Count > 200)
Form1->mMessage->Lines->Clear();

//Write the appropriate message depending on which thread this is
if (CountUp)
Form1->mMessage->Lines->Add("Count up thread " + IntToStr(Count));
else
Form1->mMessage->Lines->Add("Count down thread " + IntToStr(Count));
}
//----------------------------------------------------------------------------

sfemil 2003-10-16
  • 打赏
  • 举报
回复
http://www.yesky.com/20021022/1636272.shtml
Creating Windows CreateMDIWindow CreateWindow CreateWindowEx RegisterClass RegisterClassEx UnregisterClass Message Processing BroadcastSystemMessage CallNextHookEx CallWindowProc DefFrameProc DefMDIChildProc DefWindowProc DispatchMessage GetMessage GetMessageExtraInfo GetMessagePos GetMessageTime GetQueueStatus InSendMessage PeekMessage PostMessage PostQuitMessage PostThreadMessage RegisterWindowMessage ReplyMessage SendMessage SendMessageCallback SendMessageTimeout SendNotifyMessage SetMessageExtraInfo SetWindowsHookEx TranslateMessage UnhookWindowsHookEx WaitMessage Window Information AnyPopup ChildWindowFromPoint ChildWindowFromPointEx EnableWindow EnumChildWindows EnumPropsEx EnumThreadWindows EnumWindows FindWindow FindWindowEx GetClassInfoEx GetClassLong GetClassName GetClientRect GetDesktopWindow GetFocus GetForegroundWindow GetNextWindow GetParent GetProp GetTopWindow GetWindow GetWindowLong GetWindowRect GetWindowText GetWindowTextLength IsChild IsIconic IsWindow IsWindowEnabled IsWindowUnicode IsWindowVisible IsZoomed RemoveProp SetActiveWindow SetClassLong SetFocus SetForegroundWindow SetParent SetProp SetWindowLong SetWindowText WindowFromPoint Processes and Threads CreateEvent CreateMutex CreateProcess CreateSemaphore CreateThread DeleteCriticalSection DuplicateHandle EnterCriticalSection ExitProcess ExitThread GetCurrentProcess GetCurrentProcessId GetCurrentThread GetCurrentThreadId GetExitCodeProcess GetExitCodeThread GetPriorityClass GetThreadPriority GetWindowThreadProcessId InitializeCriticalSection InterlockedDecrement InterlockedExchange InterlockedIncrement LeaveCriticalSection OpenEvent OpenMutex OpenProcess OpenSemaphore PulseEvent ReleaseMutex ReleaseSemaphore ResetEvent ResumeThread SetEvent SetPr

1,221

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧