-
April 20th, 2005, 06:36 PM
#1
DoEvents in MFC?
my program has function that incorperates an intensive and long loop for testing purposes. i want to know if there is a function i can call, or a way to implement a function, that will check to see if there are any other events waiting in the queue to be handled. that way i can have an option to abort the process if the user so desires.
thanks,
D
-
April 20th, 2005, 06:56 PM
#2
Re: DoEvents in MFC?
well, yes
It all depends on how you are running the loop.
If you are running it in the GUI thread, (which you should not) Then you can use
GetMessage() and DispatchMessage() to pump the message queue;
here is an example
Code:
void FOO::OnClickStartButton()
{
while (true)
{
MSG msg;
while(PeekMessage(&msg, GetSafeHwnd(), 0, 0, PM_REMOVE))
{
DispatchMessage(&msg);
}
if(KillDAQ_)
{
DAQRunning_ = false;
return;
}
//// LOTS OF PROCESSING DOWN HERE
}
}
void FOO::OnClickStopButton()
{
KillDAQ_ = true;
}
If you are running the long process in a worker thread then you can use kernal event for synchronization
Code:
unsigned __stdcall FOO::WorkerThread( LPVOID pParam )
{
std::auto_ptr<FOO_WORKER_DATA> thread_data(static_cast<FOO_WORKER_DATA*>(pParam));
while(true)
{
if(WAIT_OBJECT_0 == ::WaitForSingleObject(thread_data->MurderThreadEvent_, 0))
{
return 0;
}
//LOTS OF PROCESSING DOWN HERE
}
return 0;
}
Here, MurderThreadEvent_ is an event that can be set in the gui thread or where ever.
Wakeup in the morning and kick the day in the teeth!! Or something like that.
"i don't want to write leak free code or most efficient code, like others traditional (so called expert) coders do."
-
April 21st, 2005, 01:14 AM
#3
Re: DoEvents in MFC?
MSG msg; // can be declared globally, in application source file
void DoEvents()
{
if(::PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
::TranslateMessage(&msg);
:ispatchMessage(&msg);
}
}
-
April 21st, 2005, 10:40 AM
#4
Re: DoEvents in MFC?
Thanks, that worked great!
-
April 21st, 2005, 01:45 PM
#5
Re: DoEvents in MFC?
Originally Posted by dougrockwell
Thanks, that worked great!
i think you should you souldog's second solution (worker thread)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|