title: C++ WTL8.1 How to create a window in a new thread with message loop?
body: <p>I saw this asked a lot of ways but never saw an actual working code snip.</p>
  
  <p>I tried this no doubt naive attempt to create a new thread with a new window and message loop. I have a function that must open a window &amp; process its messages, and must run in environments where it may be called from application with no existing message loop (and no other windows) or the usual mfc message loop or a WTL message loop. I saw some stuff about AddMessageLoop and Modules? but it appeared that was for the main application. In any case, there may or may not be a WTL module out there. Need a stand alone window with a basic message loop. Passing in a WTL class with window not yet opened, so Window opens in same thread as loop. Does class object also have to be created in the new thread?</p>
  
  <pre><code>// does not work.... 
  static DWORD WINAPI MyRunThread(__in LPVOID lpParameter)
  {
  CMessageLoop theLoop;
  WTLsubclass *nav = (WTLsubclass *) lpParameter;
  
  nav-&gt;CreateWindow(); 
  int nRet = theLoop.Run();
  
  return nRet;
  }
  
  CreateThread(0,0,MyRunThread,&amp;nav,0,0);
  </code></pre>