Problem with "users defined and window messages" in a thread
<p>We are developing C++ application for Windows, using Borland Code Gear 2007.</p>

<p>The main app has only one thread (this is a strong restriction). From this thread:</p>

<p>1) A Form is created (VCL from Borland).</p>

<p>2) Messages are received from both:</p>

<pre><code>a. Messages from the window: messages including Windows mouse events, etc.  (Form).

b. Our own pre-defined messages
</code></pre>

<p>3) The form is used in a Real Time application (including a camera), so this thread receives both users defined and window messages.</p>

<p>4) The thread must process ALL messages, so we cannot discard (filter) any of them.</p>

<p>The problem is:</p>

<p>Right now, when user clicks the mouse (on the FORM) and keep it pressed,
 the Application locks. Events from the mouse have a high priority than
 our own messages, so the thread keeps processing mouse events
 (until the user releases the mouse). In the meanwhile, the other type of
Messages are not processed because of the flooding of messages from the mouse, so the camera locks.</p>

<p>Any idea on how to resolve this problem? </p>

<p>Our main restriction is dealing with message priorities in one single
thread: it seems that Windows messages always arrive with the higher
priority.</p>

<p>Below you can find some code illustrating our approach:</p>

<pre><code>================================================================ 

FThread(LPVOID owner) {

  ...
  ...

  form-&gt;CreateViewController(  );

  if( form)   
 form-&gt;Show();

  while( 
  (new_event = MsgWaitForMultipleObjects( size, events, false,  INFINITE, QS_ALLINPUT )) 
         != (WAIT_OBJECT_0 + 1 )) {

 new_event = new_event - WAIT_OBJECT_0;

 if(new_event &gt;= 2 &amp;&amp; new_event!= size)

    ResetEvent( events[new_event]);

    if ( new_event &lt; size) {

    try{
     form-&gt;processMyMessages(new_event);
     }
     catch ( Exception &amp;ex) { }

    }

    if (new_event == size ) {

    MSG msg;

    while( PeekMessage( &amp;msg, 0, 0, 0, true)) {

    TranslateMessage( &amp;msg);
    DispatchMessage ( &amp;msg);

   }

    }

 }

    ...
    ...

 return 0;
}
</code></pre>
