Q:

the dialog desn't show correctly when it's created in sub-thread

I'm trying to add a pop-up message function in my project.And I make it run in a subthread since I need a realtime notification.But I find if the notification dialog is created in my subthread(started by AfxBeginThread),all the elements(buttons,urls....) of the dialog are not shown.The message box is just a blank dialog. If I extract the function and start it by a button then it works fine.Here's the function,it's quite simple.
UINT sendNotification(LPVOID pParam)
{
   int x = GetSystemMetrics(SM_CXSCREEN);
   int y = GetSystemMetrics(SM_CYSCREEN);

   testPopDlg *testPop = new testPopDlg;
   testPop->Create(IDD_TEST,0);
   CRect lprect(0,0,0,0);
   testPop->GetWindowRect(lprect);
   int w = lprect.Width();
   int h = lprect.Height();
   testPop->web.Navigate("http://www.google.com",NULL,NULL,NULL,NULL);
   testPop->ShowWindow(SW_SHOW);
   for(int k=0;k<20;k++)    //slide out
   {
      testPop->MoveWindow(x-w,y-h*k/20,w,y-h*k/20,1);
      Sleep(20);
   }
   Sleep(5000);   //will close after 5 sec
   return 0;
}

Why this function doesn't work right in subthread?

A:

To use a dialog on a different thread in MFC you should create it on a UI thread. To create a UI thread you basically have to create a class derived from CWinThread. See also this code project article.

