title: a call to GetMessage causes a thread to stop
body: <p>I am writing a multi-threaded application using Borland C++ (Delphi Forms).  I have recently learned that I can use Windows' Messaging Service within these classes when I call the PostThreadMessage() function:</p>
  
  <pre><code>System = new STSystem(SystemName,1000,1,NULL);
  while (PostThreadMessage(System-&gt;ThreadID,ST_MSG_SYSTEM_INIT,0,0) == 0)
  {
      Sleep(0);
  };
  </code></pre>
  
  <p>The above seems to work just fine.  The issue lies on the retrieval end of this process inside of the Thread Execution function:</p>
  
  <pre><code>void __fastcall STSystem::Execute()
  
  {
      ST_Message STMSG;
      while(FStatus != Destroyed)
      {
          FHeartBeat++;
          if(GetMessage(MSG,NULL,ST_MSG_SYSTEM_START,ST_MSG_SYSTEM_END))
          {
              STMSG.Value = MSG-&gt;wParam;
              if((STMSG.dSYS + (8*STMSG.dSEC) + (64*STMSG.dDEP)) == FSystemID)
              {
                  RXMessages[RxQueueIn++] = STMSG.MSG;    //  Message
                  RXMessages[RxQueueIn++] = MSG-&gt;lParam;  //  Data
              }
          }
          if(TaskList-&gt;Count&gt;0)
              ProcessTask();
          if(RxQueueIn!=RxQueueOut)
              ProcessRxMessage();
          if(TxQueueIn!=TxQueueOut)
              ProcessTxMessage();
          Sleep(0);
      };
  }
  </code></pre>
  
  <p>The above works for about two thread cycles and then stops; the thread stops, not the program.  I have tried using the PeekMessage() function instead of the GetMessage() function in the IF clause following the FHeartbeat++ counter.  This prevents the thread from stopping however, the INIT message sent in the first block of code is still not found.  </p>
  
  <p>I hope this example is not too specific.  I have tried to leave in anything that was pertinent.  Basically, this is a message pump for a class that has no window.  </p>