Click here to Skip to main content
11,488,877 members (78,991 online)
Rate this: bad
good
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
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 7-Jan-13 9:31am
Edited 8-Jan-13 0:21am
v2
Rate this: bad
good
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
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.
  Permalink  
Comments
Sergey Alexandrovich Kryukov at 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 at 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 at 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 at 7-Jan-13 15:16pm
   
Well Said.
Sergey Alexandrovich Kryukov at 7-Jan-13 15:32pm
   
Thank you.
—SA
Rate this: bad
good
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.
  Permalink  
Rate this: bad
good
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).
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 489
1 OriginalGriff 328
2 Sascha Lefèvre 135
3 _Asif_ 125
4 _duDE_ 121
0 Sergey Alexandrovich Kryukov 9,308
1 OriginalGriff 8,375
2 Sascha Lefèvre 3,334
3 Maciej Los 2,996
4 Richard Deeming 2,370


Advertise | Privacy | Mobile
Web01 | 2.8.150520.1 | Last Updated 8 Jan 2013
Copyright © CodeProject, 1999-2015
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