Click here to Skip to main content
12,882,493 members (26,243 online)
Rate this:
Please Sign up or sign in to vote.
See more: C++ MFC
Hi guys
well this time my question is not summarized in form of code. but i am asking it in different way.
I am working on mfc application and there is a condition in which i am posting window messages by using
it is executing in a loop

Now after some time if i press close button at upper left corner that is not accepting it as the reason is message loop is processing other window messages which are generated in loop. I know its straight there is way that i can do that the priority of the close window (WM_CLOSE) will be high than the other window messages.
Note: i cannot skip from posting the messages you can assume that is in loop of 30000.

any suggestion or link will be beneficial..

thanks in advance

Extended after your response Hi all first of all thanks everyone for answering. Yes there can be redesigned possible let me first tell you i do have a video recording of say 1 day. i am extracting frames on the basis of events.Suppose it is giving one frame at each second so data is extremely large. In this case what i am doing. i am extracting frame and do postmessage to display in listcontrol. Reason Why i am doing postmessage because i do not need to block the dialog(modelless) and it happening in thread data is coming continuously. Requirment: if there is any solution that i can avoid message loop will beneficial.
Posted 7-Jan-13 8:31am
Updated 7-Jan-13 23:21pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Have a look at PostQuitMessage[^] try this to comeout of the message loop.

It also says
There is a limit of 10,000 posted messages per message queue. This limit should be sufficiently large. If your application exceeds the limit, it should be redesigned to avoid consuming so many system resources. To adjust this limit, modify the following registry key.
Good answer, a 5. However, a root of the problem is wrong design of the code. Perhaps, if OP explain why doing so, I will help.
jibesh 7-Jan-13 15:04pm

'if OP explain why doing so, I will help.' that's the attitude and thats what we are called CPians :)
That's why I always recommend inquirers to start from formulation of their ultimate goals. In this case, even if OP has some misconceptions (which are very typical), she or he can get a good chance of a useful advice anyway. Our main task is to help, not just to ask a question, which can be not the most adequate to the real interests of OP.
jibesh 7-Jan-13 15:16pm
Well Said.
Thank you.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

The answer to your question is basically: No, there is no way of giving a message a higher priority than others. For the Windows designers it was more important to implement the message queue as efficiently as possible and they voluntarily abstained from "luxuries" like prioritized message handling.

There is one exception to the rule: WM_PAINT message are treated specially and are always processed last, i.e. when no other message remain in the queue; several WM_PAINTs to the same window are combined to reduce the painting overhead even further.

As SA already pointed out: Blowing some 30000 messages onto your message queue is probably not the wisest thing to do. So re-think your application and find a way to limit the number of message posts, e.g. by using a simple intermediate class that counts the number of outstanding posts and blocks the poster at a reasonable threshold -- for as long as the consuming side has processed some of those messages.

And as SA also said: If you tell us what you are actually trying to accomplish we could perhaps help with some more concrete hints.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

One of the things you can do is in your message processing loop, do a PeekMessage() periodically and look for a termination message. This will have the effect of a priority boost to the message. Don't do this frequently since this is a request to look through the entire message list until the desired message is found (ie. the entire list if it is not there).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170422.1 | Last Updated 8 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100