Click here to Skip to main content
15,891,880 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
C++
PostMessage
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 question..is 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
Updated 7-Jan-13 23:21pm
v2

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

It also says
Quote:
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.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 7-Jan-13 15:02pm    
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.
—SA
Jibesh 7-Jan-13 15:04pm    
Thanks.

'if OP explain why doing so, I will help.' that's the attitude and thats what we are called CPians :)
Sergey Alexandrovich Kryukov 7-Jan-13 15:15pm    
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.
—SA
Jibesh 7-Jan-13 15:16pm    
Well Said.
Sergey Alexandrovich Kryukov 7-Jan-13 15:32pm    
Thank you.
—SA
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.
 
Share this answer
 
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).
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900