#include <stdio.h>
 
 #include "wx/app.h"
+#include "wx/apptrait.h"
 #include "wx/module.h"
 #include "wx/intl.h"
 #include "wx/utils.h"
     }
     else // do run thread
     {
+        wxAppTraits *traits = wxTheApp ? wxTheApp->GetTraits() : NULL;
+        unsigned long ulHab;
+       if (traits)
+           traits->InitializeGui(ulHab);
         dwRet = (DWORD)pThread->Entry();
+       if (traits)
+           traits->TerminateGui(ulHab);
 
        // enter m_critsect before changing the thread state
        pThread->m_critsect.Enter();