CEvents in the message map or something similar

Hi.  What is the easiest way to get the main application thread in an MFC
application to run code when a CEvent is triggered?  I have a thread in the
application listening for incoming data from a pipe and putting it in a
queue.  I have another thread watching the queue and when there is data in
it, it will trigger the main thread to process the data.  I used this same
model on the service that is on the other end of the pipe.  It works great
because it is not MFC and has a main loop that i have WaitForMultipleObjects
function in.  In MFC, the main thread spends its idle time in MFC libraries
instead of a user-defined loop.  Can I just hook the CEvent up to a message
map so it calls a function when it is triggered?

jorj


0
jhofer1 (28)
2/25/2004 7:35:52 PM
vc.mfc 33608 articles. 0 followers. Follow

11 Replies
536 Views

Similar Articles

[PageSpeed] 30

Jordon Hofer wrote:

>Hi.  What is the easiest way to get the main application thread in an MFC
>application to run code when a CEvent is triggered?  I have a thread in the
>application listening for incoming data from a pipe and putting it in a
>queue.  I have another thread watching the queue and when there is data in
>it, it will trigger the main thread to process the data.  I used this same
>model on the service that is on the other end of the pipe.  It works great
>because it is not MFC and has a main loop that i have WaitForMultipleObjects
>function in.  In MFC, the main thread spends its idle time in MFC libraries
>instead of a user-defined loop.  Can I just hook the CEvent up to a message
>map so it calls a function when it is triggered?

No. Probably your best bet is to post a registered window message to the
main window. You could also run your own message loop and wait on the event
by using MsgWaitForMultipleObjects, but that's somewhat harder. OTOH, it
would provide you better control of when the event code is executed. If you
use the PostMessage approach, the message can be dispatched while Windows is
running a secondary message loop for you, as with a message box or during
scrollbar operations. With MWFMO, you'll notice the signaled event only when
you call MWFMO. Whether this matters or not depends on how you respond to
the event, of course.

-- 
Doug Harrison
Microsoft MVP - Visual C++
0
dsh (2498)
2/25/2004 8:02:54 PM
CEvents don't work this way. Instead, use PostMessage to notify the main GUI thread that
something interesting has happened. 

The solution you propose seems a bit clumsy. Requiring two threads seems unnecessary.
However, if you are going to have a high data rate of messages, PostMessage doesn't work
terribly well; you might want to consider my use of I/O Completion Ports (see my essay on
this subject on my MVP Tips site), where the I/O Completion Port provides the queueing.

The last time I looked, MFC did not "spend its idle time in MFC libraries instead of a
user-defined loop", and your illusion that this is so is incorrect. What it does is just
once call the cleanup of temporary objects. So you have probably cretaed a solution that
is solving a nonexistent problem for the wrong reasons. In fact, I show in my essay how to
use the OnIdle handler in MFC to optimize throughput when an I/O completion port is used.
This looks very much like a way to introduce the functionality you want.

You are very, very confused about CEvents; they have nothing to do with message maps. They
are simple boolean values that happen to be waitable. But I think they represent the wrong
solution to your problem. Note that if you have a queue, you probably want semaphores
instead of events anyway (see my essay on semaphores on my MVP Tips site) but it sounds
like either PostMessage or I/O Completion Ports would be a better solution.

In any case, creating solutions based on incorrect illusions and false information usually
leads to solutions that have been warped for the wrong reasons. I'm not sure where you got
the idea that the main thread spends time looping in MFC libraries instead of blocking,
but you are wrong, and a careful reading of the code demonstrates this. Likewise, your
illusion that you can't inject your own code into the message loop is also wrong, which my
essay demonstrates.
				joe

On Wed, 25 Feb 2004 13:35:52 -0600, "Jordon Hofer" <jhofer@agsense.REMOVETHIS.net> wrote:

>Hi.  What is the easiest way to get the main application thread in an MFC
>application to run code when a CEvent is triggered?  I have a thread in the
>application listening for incoming data from a pipe and putting it in a
>queue.  I have another thread watching the queue and when there is data in
>it, it will trigger the main thread to process the data.  I used this same
>model on the service that is on the other end of the pipe.  It works great
>because it is not MFC and has a main loop that i have WaitForMultipleObjects
>function in.  In MFC, the main thread spends its idle time in MFC libraries
>instead of a user-defined loop.  Can I just hook the CEvent up to a message
>map so it calls a function when it is triggered?
>
>jorj
>

Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15974)
2/25/2004 9:11:48 PM
Wow.  Thank you for that response.  My MFC likes to "spend its idle time in
MFC libraries instead of a user-defined loop" came out a little sloppier
than i intended.  I realize that it does some behind the scenes stuff but
most likely sleeps a lot.  I used that phrase to focus on my main point: in
a non-mfc program, the main thread spends its idle time in a loop that you
have to create.  In an mfc one, you dont worry about that.

From my understanding, CEvents are just MFC classes to encapsulate a
CRITICAL_SECTION and the EnterCriticalSection/ExitCriticalSection functions.
My reason for posting was asking if there was an easy way to connect a
CEvent to message maps.  I didnt see any documentation on it, but I was
still hoping. :)  It looks like I will go with the PostMessage method unless
some big issue pops up.

Thanks again for the input.  I bookmarked your website.  It looks like it
has a ton of great information.

jorj


"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message
news:lb3q305csuut34ve1fr14vl98l0nfu8hls@4ax.com...
> CEvents don't work this way. Instead, use PostMessage to notify the main
GUI thread that
> something interesting has happened.
>
> The solution you propose seems a bit clumsy. Requiring two threads seems
unnecessary.
> However, if you are going to have a high data rate of messages,
PostMessage doesn't work
> terribly well; you might want to consider my use of I/O Completion Ports
(see my essay on
> this subject on my MVP Tips site), where the I/O Completion Port provides
the queueing.
>
> The last time I looked, MFC did not "spend its idle time in MFC libraries
instead of a
> user-defined loop", and your illusion that this is so is incorrect. What
it does is just
> once call the cleanup of temporary objects. So you have probably cretaed a
solution that
> is solving a nonexistent problem for the wrong reasons. In fact, I show in
my essay how to
> use the OnIdle handler in MFC to optimize throughput when an I/O
completion port is used.
> This looks very much like a way to introduce the functionality you want.
>
> You are very, very confused about CEvents; they have nothing to do with
message maps. They
> are simple boolean values that happen to be waitable. But I think they
represent the wrong
> solution to your problem. Note that if you have a queue, you probably want
semaphores
> instead of events anyway (see my essay on semaphores on my MVP Tips site)
but it sounds
> like either PostMessage or I/O Completion Ports would be a better
solution.
>
> In any case, creating solutions based on incorrect illusions and false
information usually
> leads to solutions that have been warped for the wrong reasons. I'm not
sure where you got
> the idea that the main thread spends time looping in MFC libraries instead
of blocking,
> but you are wrong, and a careful reading of the code demonstrates this.
Likewise, your
> illusion that you can't inject your own code into the message loop is also
wrong, which my
> essay demonstrates.
> joe
>
> On Wed, 25 Feb 2004 13:35:52 -0600, "Jordon Hofer"
<jhofer@agsense.REMOVETHIS.net> wrote:
>
> >Hi.  What is the easiest way to get the main application thread in an MFC
> >application to run code when a CEvent is triggered?  I have a thread in
the
> >application listening for incoming data from a pipe and putting it in a
> >queue.  I have another thread watching the queue and when there is data
in
> >it, it will trigger the main thread to process the data.  I used this
same
> >model on the service that is on the other end of the pipe.  It works
great
> >because it is not MFC and has a main loop that i have
WaitForMultipleObjects
> >function in.  In MFC, the main thread spends its idle time in MFC
libraries
> >instead of a user-defined loop.  Can I just hook the CEvent up to a
message
> >map so it calls a function when it is triggered?
> >
> >jorj
> >
>
> Joseph M. Newcomer [MVP]
> email: newcomer@flounder.com
> Web: http://www.flounder.com
> MVP Tips: http://www.flounder.com/mvp_tips.htm


0
jhofer1 (28)
2/25/2004 10:37:19 PM
No, CEvents are MFC objects that are used to wrap Event objects. CRITICAL_SECTIONS are
wrapped by something else, and in any case the general opinion is that the MFC classes for
synhcronization suck and are best ignored.  None of these mechanisms have anything to do
with message maps.

				jor

On Wed, 25 Feb 2004 16:37:19 -0600, "Jordon Hofer" <jhofer@agsense.REMOVETHIS.net> wrote:

>Wow.  Thank you for that response.  My MFC likes to "spend its idle time in
>MFC libraries instead of a user-defined loop" came out a little sloppier
>than i intended.  I realize that it does some behind the scenes stuff but
>most likely sleeps a lot.  I used that phrase to focus on my main point: in
>a non-mfc program, the main thread spends its idle time in a loop that you
>have to create.  In an mfc one, you dont worry about that.
>
>From my understanding, CEvents are just MFC classes to encapsulate a
>CRITICAL_SECTION and the EnterCriticalSection/ExitCriticalSection functions.
>My reason for posting was asking if there was an easy way to connect a
>CEvent to message maps.  I didnt see any documentation on it, but I was
>still hoping. :)  It looks like I will go with the PostMessage method unless
>some big issue pops up.
>
>Thanks again for the input.  I bookmarked your website.  It looks like it
>has a ton of great information.
>
>jorj
>
>
>"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message
>news:lb3q305csuut34ve1fr14vl98l0nfu8hls@4ax.com...
>> CEvents don't work this way. Instead, use PostMessage to notify the main
>GUI thread that
>> something interesting has happened.
>>
>> The solution you propose seems a bit clumsy. Requiring two threads seems
>unnecessary.
>> However, if you are going to have a high data rate of messages,
>PostMessage doesn't work
>> terribly well; you might want to consider my use of I/O Completion Ports
>(see my essay on
>> this subject on my MVP Tips site), where the I/O Completion Port provides
>the queueing.
>>
>> The last time I looked, MFC did not "spend its idle time in MFC libraries
>instead of a
>> user-defined loop", and your illusion that this is so is incorrect. What
>it does is just
>> once call the cleanup of temporary objects. So you have probably cretaed a
>solution that
>> is solving a nonexistent problem for the wrong reasons. In fact, I show in
>my essay how to
>> use the OnIdle handler in MFC to optimize throughput when an I/O
>completion port is used.
>> This looks very much like a way to introduce the functionality you want.
>>
>> You are very, very confused about CEvents; they have nothing to do with
>message maps. They
>> are simple boolean values that happen to be waitable. But I think they
>represent the wrong
>> solution to your problem. Note that if you have a queue, you probably want
>semaphores
>> instead of events anyway (see my essay on semaphores on my MVP Tips site)
>but it sounds
>> like either PostMessage or I/O Completion Ports would be a better
>solution.
>>
>> In any case, creating solutions based on incorrect illusions and false
>information usually
>> leads to solutions that have been warped for the wrong reasons. I'm not
>sure where you got
>> the idea that the main thread spends time looping in MFC libraries instead
>of blocking,
>> but you are wrong, and a careful reading of the code demonstrates this.
>Likewise, your
>> illusion that you can't inject your own code into the message loop is also
>wrong, which my
>> essay demonstrates.
>> joe
>>
>> On Wed, 25 Feb 2004 13:35:52 -0600, "Jordon Hofer"
><jhofer@agsense.REMOVETHIS.net> wrote:
>>
>> >Hi.  What is the easiest way to get the main application thread in an MFC
>> >application to run code when a CEvent is triggered?  I have a thread in
>the
>> >application listening for incoming data from a pipe and putting it in a
>> >queue.  I have another thread watching the queue and when there is data
>in
>> >it, it will trigger the main thread to process the data.  I used this
>same
>> >model on the service that is on the other end of the pipe.  It works
>great
>> >because it is not MFC and has a main loop that i have
>WaitForMultipleObjects
>> >function in.  In MFC, the main thread spends its idle time in MFC
>libraries
>> >instead of a user-defined loop.  Can I just hook the CEvent up to a
>message
>> >map so it calls a function when it is triggered?
>> >
>> >jorj
>> >
>>
>> Joseph M. Newcomer [MVP]
>> email: newcomer@flounder.com
>> Web: http://www.flounder.com
>> MVP Tips: http://www.flounder.com/mvp_tips.htm
>

Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15974)
2/26/2004 1:07:28 AM
"Jordon Hofer" <jhofer@agsense.REMOVETHIS.net> wrote in message
news:6JGdnc3h-YaHZKHdRVn-iQ@rapidnet.com...
> Hi.  What is the easiest way to get the main application thread in an MFC
> application to run code when a CEvent is triggered?  I have a thread in
the
> application listening for incoming data from a pipe and putting it in a
> queue.  I have another thread watching the queue and when there is data in
> it, it will trigger the main thread to process the data.  I used this same
> model on the service that is on the other end of the pipe.  It works great
> because it is not MFC and has a main loop that i have
WaitForMultipleObjects
> function in.  In MFC, the main thread spends its idle time in MFC
libraries
> instead of a user-defined loop.  Can I just hook the CEvent up to a
message
> map so it calls a function when it is triggered?
>
> jorj
>
If you use a worker thread, then everything becomes very simple. It's
basically like sticking a loop that you're familiar with on the side of the
main thread. You use your WaitForMultipleObjects, then post a message to
your main thread to tell it to do something.

Jaes


0
jshelley (197)
2/26/2004 1:56:22 AM
man, today was a long one.  I was looking at the CCriticalSection class when
I wrote that last reply and I guess my brain garbled them together.  my
bad...

jorj



"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message
news:kchq305hpkebdl37e8epf3igh49pvu55qh@4ax.com...
> No, CEvents are MFC objects that are used to wrap Event objects.
CRITICAL_SECTIONS are
> wrapped by something else, and in any case the general opinion is that the
MFC classes for
> synhcronization suck and are best ignored.  None of these mechanisms have
anything to do
> with message maps.
>
> jor
>
> On Wed, 25 Feb 2004 16:37:19 -0600, "Jordon Hofer"
<jhofer@agsense.REMOVETHIS.net> wrote:
>
> >Wow.  Thank you for that response.  My MFC likes to "spend its idle time
in
> >MFC libraries instead of a user-defined loop" came out a little sloppier
> >than i intended.  I realize that it does some behind the scenes stuff but
> >most likely sleeps a lot.  I used that phrase to focus on my main point:
in
> >a non-mfc program, the main thread spends its idle time in a loop that
you
> >have to create.  In an mfc one, you dont worry about that.
> >
> >From my understanding, CEvents are just MFC classes to encapsulate a
> >CRITICAL_SECTION and the EnterCriticalSection/ExitCriticalSection
functions.
> >My reason for posting was asking if there was an easy way to connect a
> >CEvent to message maps.  I didnt see any documentation on it, but I was
> >still hoping. :)  It looks like I will go with the PostMessage method
unless
> >some big issue pops up.
> >
> >Thanks again for the input.  I bookmarked your website.  It looks like it
> >has a ton of great information.
> >
> >jorj
> >
> >
> >"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message
> >news:lb3q305csuut34ve1fr14vl98l0nfu8hls@4ax.com...
> >> CEvents don't work this way. Instead, use PostMessage to notify the
main
> >GUI thread that
> >> something interesting has happened.
> >>
> >> The solution you propose seems a bit clumsy. Requiring two threads
seems
> >unnecessary.
> >> However, if you are going to have a high data rate of messages,
> >PostMessage doesn't work
> >> terribly well; you might want to consider my use of I/O Completion
Ports
> >(see my essay on
> >> this subject on my MVP Tips site), where the I/O Completion Port
provides
> >the queueing.
> >>
> >> The last time I looked, MFC did not "spend its idle time in MFC
libraries
> >instead of a
> >> user-defined loop", and your illusion that this is so is incorrect.
What
> >it does is just
> >> once call the cleanup of temporary objects. So you have probably
cretaed a
> >solution that
> >> is solving a nonexistent problem for the wrong reasons. In fact, I show
in
> >my essay how to
> >> use the OnIdle handler in MFC to optimize throughput when an I/O
> >completion port is used.
> >> This looks very much like a way to introduce the functionality you
want.
> >>
> >> You are very, very confused about CEvents; they have nothing to do with
> >message maps. They
> >> are simple boolean values that happen to be waitable. But I think they
> >represent the wrong
> >> solution to your problem. Note that if you have a queue, you probably
want
> >semaphores
> >> instead of events anyway (see my essay on semaphores on my MVP Tips
site)
> >but it sounds
> >> like either PostMessage or I/O Completion Ports would be a better
> >solution.
> >>
> >> In any case, creating solutions based on incorrect illusions and false
> >information usually
> >> leads to solutions that have been warped for the wrong reasons. I'm not
> >sure where you got
> >> the idea that the main thread spends time looping in MFC libraries
instead
> >of blocking,
> >> but you are wrong, and a careful reading of the code demonstrates this.
> >Likewise, your
> >> illusion that you can't inject your own code into the message loop is
also
> >wrong, which my
> >> essay demonstrates.
> >> joe
> >>
> >> On Wed, 25 Feb 2004 13:35:52 -0600, "Jordon Hofer"
> ><jhofer@agsense.REMOVETHIS.net> wrote:
> >>
> >> >Hi.  What is the easiest way to get the main application thread in an
MFC
> >> >application to run code when a CEvent is triggered?  I have a thread
in
> >the
> >> >application listening for incoming data from a pipe and putting it in
a
> >> >queue.  I have another thread watching the queue and when there is
data
> >in
> >> >it, it will trigger the main thread to process the data.  I used this
> >same
> >> >model on the service that is on the other end of the pipe.  It works
> >great
> >> >because it is not MFC and has a main loop that i have
> >WaitForMultipleObjects
> >> >function in.  In MFC, the main thread spends its idle time in MFC
> >libraries
> >> >instead of a user-defined loop.  Can I just hook the CEvent up to a
> >message
> >> >map so it calls a function when it is triggered?
> >> >
> >> >jorj
> >> >
> >>
> >> Joseph M. Newcomer [MVP]
> >> email: newcomer@flounder.com
> >> Web: http://www.flounder.com
> >> MVP Tips: http://www.flounder.com/mvp_tips.htm
> >
>
> Joseph M. Newcomer [MVP]
> email: newcomer@flounder.com
> Web: http://www.flounder.com
> MVP Tips: http://www.flounder.com/mvp_tips.htm


0
jhofer1 (28)
2/26/2004 3:02:30 AM
There are also ATL classes (ATL::CEvent), which are more lightweight and
convenient.

"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message
news:kchq305hpkebdl37e8epf3igh49pvu55qh@4ax.com...
> No, CEvents are MFC objects that are used to wrap Event objects.
CRITICAL_SECTIONS are
> wrapped by something else, and in any case the general opinion is that the
MFC classes for
> synhcronization suck and are best ignored.  None of these mechanisms have
anything to do
> with message maps.
>
> jor
>


0
alegr (1131)
2/26/2004 3:25:04 AM
http://support.microsoft.com/support/kb/articles/Q197/7/28.asp
Creating a Thread Pool for MFC-Based ISAPI Extensions

-- 
Command what is yours
Conquer what is not
Microsoft Most Valuable Professional [VC++]
http://www.csdn.net/develop/author/netauthor/jiangsheng/
http://blog.joycode.com/jiangsheng/
http://jiangsheng.blogone.net
"Jordon Hofer" <jhofer@agsense.REMOVETHIS.net> д���ʼ�
news:6JGdnc3h-YaHZKHdRVn-iQ@rapidnet.com...
> Hi.  What is the easiest way to get the main application thread in an MFC
> application to run code when a CEvent is triggered?  I have a thread in
the
> application listening for incoming data from a pipe and putting it in a
> queue.  I have another thread watching the queue and when there is data in
> it, it will trigger the main thread to process the data.  I used this same
> model on the service that is on the other end of the pipe.  It works great
> because it is not MFC and has a main loop that i have
WaitForMultipleObjects
> function in.  In MFC, the main thread spends its idle time in MFC
libraries
> instead of a user-defined loop.  Can I just hook the CEvent up to a
message
> map so it calls a function when it is triggered?
>
> jorj
>
>


0
sheng_jiang (305)
2/26/2004 4:24:25 AM
This is pretty much the approach I am attempting.  I have hit a snag
however.  I do most of my work out the the main application class file (the
CWinApp derived one) because I can easily have all the various parts of the
program get the data they need from here.  I post the message using
theApp.m_pMainWnd->SendMessage(CM_ITEMINQUEUE, 0, 0);

I cannot field the message.  I cannot set up the ON_MESSAGE handler here
because it is not CWnd derived.  I go to the MainFrm class and set up the
handler there because it is CFrameWnd derived and it builds but does not get
the message.  If it would get the message here, I could have it call a
function that is back in the CWinApp derived class to do the work.  Any
ideas?

jorj



"Jase" <jshelley@spamblock.enersol.com.au> wrote in message
news:403d5246$0$15134$afc38c87@news.optusnet.com.au...
> "Jordon Hofer" <jhofer@agsense.REMOVETHIS.net> wrote in message
> news:6JGdnc3h-YaHZKHdRVn-iQ@rapidnet.com...
> > Hi.  What is the easiest way to get the main application thread in an
MFC
> > application to run code when a CEvent is triggered?  I have a thread in
> the
> > application listening for incoming data from a pipe and putting it in a
> > queue.  I have another thread watching the queue and when there is data
in
> > it, it will trigger the main thread to process the data.  I used this
same
> > model on the service that is on the other end of the pipe.  It works
great
> > because it is not MFC and has a main loop that i have
> WaitForMultipleObjects
> > function in.  In MFC, the main thread spends its idle time in MFC
> libraries
> > instead of a user-defined loop.  Can I just hook the CEvent up to a
> message
> > map so it calls a function when it is triggered?
> >
> > jorj
> >
> If you use a worker thread, then everything becomes very simple. It's
> basically like sticking a loop that you're familiar with on the side of
the
> main thread. You use your WaitForMultipleObjects, then post a message to
> your main thread to tell it to do something.
>
> Jaes
>
>


0
jhofer1 (28)
2/26/2004 4:47:44 PM
nm
ON_REGISTERED_MESSAGE works better than ON_MESSAGE because...well... it
works!

jorj


"Jordon Hofer" <jhofer@agsense.REMOVETHIS.net> wrote in message
news:cradneHJn7euvqPdRVn-ig@rapidnet.com...
> This is pretty much the approach I am attempting.  I have hit a snag
> however.  I do most of my work out the the main application class file
(the
> CWinApp derived one) because I can easily have all the various parts of
the
> program get the data they need from here.  I post the message using
> theApp.m_pMainWnd->SendMessage(CM_ITEMINQUEUE, 0, 0);
>
> I cannot field the message.  I cannot set up the ON_MESSAGE handler here
> because it is not CWnd derived.  I go to the MainFrm class and set up the
> handler there because it is CFrameWnd derived and it builds but does not
get
> the message.  If it would get the message here, I could have it call a
> function that is back in the CWinApp derived class to do the work.  Any
> ideas?
>
> jorj
>
>
>
> "Jase" <jshelley@spamblock.enersol.com.au> wrote in message
> news:403d5246$0$15134$afc38c87@news.optusnet.com.au...
> > "Jordon Hofer" <jhofer@agsense.REMOVETHIS.net> wrote in message
> > news:6JGdnc3h-YaHZKHdRVn-iQ@rapidnet.com...
> > > Hi.  What is the easiest way to get the main application thread in an
> MFC
> > > application to run code when a CEvent is triggered?  I have a thread
in
> > the
> > > application listening for incoming data from a pipe and putting it in
a
> > > queue.  I have another thread watching the queue and when there is
data
> in
> > > it, it will trigger the main thread to process the data.  I used this
> same
> > > model on the service that is on the other end of the pipe.  It works
> great
> > > because it is not MFC and has a main loop that i have
> > WaitForMultipleObjects
> > > function in.  In MFC, the main thread spends its idle time in MFC
> > libraries
> > > instead of a user-defined loop.  Can I just hook the CEvent up to a
> > message
> > > map so it calls a function when it is triggered?
> > >
> > > jorj
> > >
> > If you use a worker thread, then everything becomes very simple. It's
> > basically like sticking a loop that you're familiar with on the side of
> the
> > main thread. You use your WaitForMultipleObjects, then post a message to
> > your main thread to tell it to do something.
> >
> > Jaes
> >
> >
>
>


0
jhofer1 (28)
2/26/2004 9:45:29 PM
SendMessage is a fundamentally bad idea. Change it to PostMessage. SendMessage can get you
into deadlock problems.

The thread should not be touching the app class; pass the CWnd * into the thread as a
parameter.

If you are posting a message to the main thread, why are you saying it is not
CWnd-derived? The main window of any MFC app is CWnd-derived.

If you put the handler in the CMainFrame, you need to post the message to the CMainFrame.

It is meaningless to post a message to the app class.
				joe

On Thu, 26 Feb 2004 10:47:44 -0600, "Jordon Hofer" <jhofer@agsense.REMOVETHIS.net> wrote:

>This is pretty much the approach I am attempting.  I have hit a snag
>however.  I do most of my work out the the main application class file (the
>CWinApp derived one) because I can easily have all the various parts of the
>program get the data they need from here.  I post the message using
>theApp.m_pMainWnd->SendMessage(CM_ITEMINQUEUE, 0, 0);
>
>I cannot field the message.  I cannot set up the ON_MESSAGE handler here
>because it is not CWnd derived.  I go to the MainFrm class and set up the
>handler there because it is CFrameWnd derived and it builds but does not get
>the message.  If it would get the message here, I could have it call a
>function that is back in the CWinApp derived class to do the work.  Any
>ideas?
>
>jorj
>
>
>
>"Jase" <jshelley@spamblock.enersol.com.au> wrote in message
>news:403d5246$0$15134$afc38c87@news.optusnet.com.au...
>> "Jordon Hofer" <jhofer@agsense.REMOVETHIS.net> wrote in message
>> news:6JGdnc3h-YaHZKHdRVn-iQ@rapidnet.com...
>> > Hi.  What is the easiest way to get the main application thread in an
>MFC
>> > application to run code when a CEvent is triggered?  I have a thread in
>> the
>> > application listening for incoming data from a pipe and putting it in a
>> > queue.  I have another thread watching the queue and when there is data
>in
>> > it, it will trigger the main thread to process the data.  I used this
>same
>> > model on the service that is on the other end of the pipe.  It works
>great
>> > because it is not MFC and has a main loop that i have
>> WaitForMultipleObjects
>> > function in.  In MFC, the main thread spends its idle time in MFC
>> libraries
>> > instead of a user-defined loop.  Can I just hook the CEvent up to a
>> message
>> > map so it calls a function when it is triggered?
>> >
>> > jorj
>> >
>> If you use a worker thread, then everything becomes very simple. It's
>> basically like sticking a loop that you're familiar with on the side of
>the
>> main thread. You use your WaitForMultipleObjects, then post a message to
>> your main thread to tell it to do something.
>>
>> Jaes
>>
>>
>

Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15974)
2/27/2004 4:07:56 AM
Reply:

Similar Artilces:

Transfering messages
I want to transfer all my messages from one PC running Vista to another running Win7 which I have Windows Mail running on. However, I have two problems: 1. On transferring some of the transferred folders contain the full message, some only contain what you might call place holders e.g my transferred Inbox has 'From' with a list of 30 or so messages but just shows an envelop and the date and time but no message 2. Is there away to transfer attachments too? -- Ron "Ron O'Brien" <castcall@ntlworld.com> wrote in message news:uBH3g6UjKHA.218...

Possible to globally set fields in messages views?
I have numerous folders and subfolders in my in-box. I now have Outlook 2003 on WinXP, formerly using Outlook 2000 on Win2k. In neither one can I find a way to either change the e-mail default fields once and for all (in which case I'd want one default for in-coming and another for out-going), or to change existing folders all at once (in which case I'd again want to set all in-box folders one way and all sent folders another way. Is there any way to do this? If so, how? Thanks. -- Bob Bob <xxxx@xxxxx.com> wrote: > I have numerous folders and subfolders in my in-box. I n...

0x800CCC90 error message Outlook 2003
"Receiving' reported error (0x800CCC90) : 'Your incoming (POP3) e-mail server has reported an internal error. If you continue to receive this message, contact your server administrator or Internet service provider (ISP). Server responded: -ERR problem retrieving message. Moved from Outlook 2000 to Outlook 2003 with the purchase of a new computer and trying to set up the email accounts for myself and my wife with our ISP. Set up my wife's account, and she's able to send and receive no problem. I used the exact same setup routine on my account, and ran into "...

Unencrypted Messages
We receive some email message from our peers in a university setting who do not use Outlook. We are unable to read the body of their email messages. We can read the subject line but that is all. We also received a "Notepad" attachment. Below is the message we received from the university's IT staff "The university server can read your messages, but the university messages to you are not encrypted. Your software, apparently Microscoft Exchange, unencrypts the already unencrypted messages that I send you, transforming the legible to illegible." Any ideas on how to re...

send messages through POS
I have a client that has 4 stores and HQ and wants to use the feature of sending messages(email) in the pos systems. Are they able to send messages to each other at other stores or this is for local store only. Thanks Dave This is a multi-part message in MIME format. ------=_NextPart_000_005E_01CB146B.321738F0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Dave, Unfortunately, it can only be done with an add-on. Check with Retail = Realm www.retailrealm.co.uk as one who offers one. --=20 Jeff=20 Check Point Software...

Invalid Parameter Error Message
When I try to enter a new contact in Outlook 2007, I get the error message: "Could not complete the operation. One or more parameter values are not valid." I am able to revise and save existing contact information. I am working offline, if that makes a difference. Does anyone know how to fix this? -- HJ "HJ" <HJ@discussions.microsoft.com> wrote in message news:10BB7932-39BB-45B8-8D29-70DC5D5BCDE2@microsoft.com... > When I try to enter a new contact in Outlook 2007, I get the error message: > "Could not complete the operation. One or ...

Is there no way to view individual messages in Exchange 03?
After much Googling, I've learned: 1) Exchange 2003 disabled the "M drive" feature, and 2) Messing around with individual messages in the M drive is a bad idea anyhow. So, is there anyway from the Exchange 03 System Manager to view/open/manage individual email messages? Or must I use Outlook or OWA to do this? Thanks... N2 You need Outlook or OWA to do it... -- -- Brian Desmond Windows Server MVP desmondb@payton.cps.k12.il.us Http://www.briandesmond.com "N2" <none@nunya.com> wrote in message news:_VNud.4773$ve.2836@fed1read06... > After much Go...

Threading Messages
Does anyone know how to set up "threads" of messages in your INBOX to keep track of all related correspondence? Try (in OL 2002) View > Current View > By Conversation Topic K "Robert BURR" <anonymous@discussions.microsoft.com> wrote in message news:0bcc01c3be7c$97323ce0$a001280a@phx.gbl... > Does anyone know how to set up "threads" of messages in > your INBOX to keep track of all related correspondence? Thank You!! >-----Original Message----- >Try (in OL 2002) >View > Current View > By Conversation Topic >K > >"...

Export "Received" timestamp from Outlook Messages
I am trying to build a database that will track responses to and from an email group. I would like to export the timestamp in the "Received" or "Sent" fields. The standard export feature in Outlook does not include these fields. Does anybody have a suggestion on how I can capture these fields in my export file. Thanks, Ken ...

won't view last message received
This started happening in the last day or two. When I open a folder in Windows Mail (Inbox, Deleted Items, Sent Items, etc.), it goes directly to (views) the oldest message instead of the newest message. Windows Mail has always defaulted to the last message received when clicking on a folder. I don't want to see the oldest message, for instance, if I click on the Junk E-mail folder, I want to see the newest message. I don't want to have to scroll all the way down from the top. Is there a way to change this back to the way it has always been? I've done some search...

Messages in Outbox 2003 Outbox do not get sent
If I have messages in the Outlook 2003 Outbox ready for sending, and I click on that folder to look at the list of those messages (without opening the messages themselves), Outlook no longer sends those messages the next time a Send is done. However, if I arrange that folder so that messages are arranged in groups (e.g., by date), and the group is not expanded, that is, the message is hidden inside the group, this behaviour does not occur, and the message is indeed sent next time. This must be bug. Microsoft, Help! ...

NDR: Unable to deliver message to <blah>, because the message was forwarded more than the maximum allowed times. This could indicate a mail loop.
I have started seeing lots of messages generating the folowing NDR: Unable to deliver message to the following recipients, because the message was forwarded more than the maximum allowed times. This could indicate a mail loop. I assume this is some MTA's peeking into headers and counting hops. Our exchange is internal, and outbound email is forwarded to an external smtp proxy. I am becoming conerned at the frequency of these. Is there some popular mail handler, or spam filter that could be responsible for these ?? Info appreciated. Bob Bob - Any idea what your hop count is se...

When I right Click on a message, I need a NEW message
When I right click on a message, a menu pops out. I need to send a new email to that contact. Reply will insert the old message. I don't need the old message. ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this link to open the suggestion in the Microsoft Web-based Newsreader and then click "I Agree" in the message pane. http://www.microsoft.com/office/community/en-us/default.m...

customizing outgoing email messages
Hello, Does anyone know how to create email messages by using a custom template? What I am trying to do is insert my logo as the backgroung for all of my outgoing mail. The logo was originally in Illustrator and I have tried to save it in every format imaginable but can't upload as a template when I am in Outlook. Please help. ...

Message Box
Draft 1 Sub MsgBoxmacro() MsgBox "Question #1 here" MsgBox "Question #2 here" MsgBox "Question #3 here" MsgBox "Question #4 here" MsgBox "Question #5 here" MsgBox "Question #6 here" MsgBox "Question #7 here" End Sub Draft 2 Option Explicit Sub MsgBoxmacro() Dim ans1 As String Dim BMs As Bookmarks Dim rng As Word.Range Set BMs = ActiveDocument.Bookmarks ans1 = InputBox("Enter your first name", "Answer #1") If Len(ans1) > 0 Then Set rng = BMs("ans1").Range rng.Te...

test message
test message ...

Printing an Email Message (but only 1 page)
Hi, when I go to print an email (in Microsoft Outlook), I press "file", then "print", and usually I get a window asking "Print pages -- "all" or "page numbers.." etc, but I don't always get this screen. Sometimes, (depending on the email), I get "print all pages, print only odd pages, or print only even pages". How can I only print the current page, all the time? Thank you! ...

Dynamic field mapping with excel import
Hi, I'm new to access2007 but have a bit of experience with VBA in excel. I inherited a lot of excel files that I'm trying to import into a single table in Access. I've written a short VBA program to cycle through the excel files and grab the relevant ranges from the various sheets in each workbook. Which is how I discovered that most of the forms have small differences that cause Access to throw an error during the import process. The excel files are essentially forms but unfortunately there was no quality control on the forms so that the header information varie...

messages are copyied not moved
Hello everyone, this is my fist time posting to this newsgroup. My questions has to do with the junk email filter.When I set it up under "Organize" so that all "Junk" and "Adult Content" email will be "moved" to "Deleted Items" why does it copy them there instead of moving them there. This is so annoying because then I still have to go and delete them from all personal folders. Thanks in advanced and I look forward to hearing a response. john Odds are that you have another rule that is conflicting with the "junk/adult" rule. Fi...

Outlook message in Excel
Hello, In OUTLOOK 2000, I receive many emails that have messages set in the same structure. I am able to copy and paste the message in my Excel spreadsheet, and then manipulate the data. The problem is I have about 100 emails/day to look at, and I would love to have to process automated Say I have all my emails in a directory Personal\Inbox\data I would like to copy /paste all the messages into ONE Excel sheet, all one after the other in column A. Can this be done? Many thanks in advance Andr� Hi Andre See http://www.dicks-clicks.com/excel/olRetrieving.htm -- Regards Ron de Bru...

Outlook Messages
I just installed a new hard drive and set my old one as a slave. How can I retrieve my messages from the old drive into Outlook on my new drive? I do not know where to llok for the files on the old drive in explorer. My old drive does not have a functiong OS. Thanks On Mon, 28 Jul 2003 05:03:21 -0700, "michael" <michael.hale@unicomcentral.com> wrote: >I just installed a new hard drive and set my old one as a >slave. How can I retrieve my messages from the old drive >into Outlook on my new drive? I do not know where to llok >for the files on the old dr...

CEvent
Sorry for asking this doubt,in my timer call back,creating 3 thread for reading file etc..critical section using for synchronization(i did just enter critical section),i have to continue my work in timer until thread finish loading that file . just i am using Global variable(static member of gloabalclass) to check whether this file opened or not,i believe this is not good way to do it,(must i use CEvent or something?)anybody can explain what is the best way to do it?syntax would be great helpful to me.. thanks.. <keralafood@gmail.com> wrote in message news:1193029056.903166.231400@e3...

tracking e-mail messages
can you track what PC and what NT user sent an e-mail? and how do you do it? any help would be appreciated. thanks, JOE ...

NDR Message 5.7.1
I have a problem with message beging recieved through our exchange server. This recently started. One of our other admins did some tweaking before he went out of town and we are having a hard time finding out what was done and yes we have tried to contact him. Mail sent from exchange users come in fine but when sent from external addresses (the ones we have tested) do not come in and get a ndr message. I don't know how long this has been happening exactly but it has been a week since the other admin left. Used both DNSreports / DNSstuff and oddly both have the MX and DNS succes...

Message Tracking with Message ID
I work on the Defense Message System. We get error reports for messages with a message ID on them. The problem is how does one find the message that goes with the ID in a "FIND" of the Sent Items on the senders computer? I have not found a way that is user friendly to do this search on the users computer. Very Respectfully, ET3 Hettinger USN ...