Dialog not diap[layed when using threads

When I run this code CMyDialog isn't displayed.  Does anyone know why.
Should I make it as a modeless dialog?


UINT myThread(LPVOID param)
{

      CMyDialog dlg;
      dlg.DoModal();

      return 1;
}


void thisTakesTime()
{
      for (int i = 0; i < 10; i++) {
            CString s = "hello";
            if (i == 9)
                  i = 1;      // never leave loop
      }
}


void CTaskbartestDlg::OnGoButton()
{

    CWinThread* thread = AfxBeginThread(myThread, 0);
    thisTakesTime();
}
LVL 1
MothAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MothAuthor Commented:
Adjusted points to 100
0
mnbmnbCommented:
Becouse you call dialog, your new thread is UI thread. For UI thread you must declare new class.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mnbmnbCommented:
For example:

class MyThread: public CWinThread
{
      DECLARE_DYNCREATE(MyThread)
protected:
      MyThread();           // protected constructor used by dynamic creation

// Attributes
public:
      YorDialog yourdialog;
// Operations
public:

// Overrides
      // ClassWizard generated virtual function overrides
      //{{AFX_VIRTUAL(MyThread)
      public:
      virtual BOOL InitInstance();
      virtual int ExitInstance();
      //}}AFX_VIRTUAL

// Implementation
protected:
      virtual ~MyThread();

      // Generated message map functions
      //{{AFX_MSG(MyThread)
            // NOTE - the ClassWizard will add and remove member functions here.
      //}}AFX_MSG

      DECLARE_MESSAGE_MAP()
};

IMPLEMENT_DYNCREATE(MyThread, CWinThread)

MyThread::MyThread()
{
}

MyThread::~MyThread()
{
}

BOOL MyThread::InitInstance()
{
  //You show your dialog here
}

int MyThread::ExitInstance()
{

      return CWinThread::ExitInstance();
}


You must call your thread as follows:

AfxBeginThread(RUNTIME_CLASS(MyThread));
0
MothAuthor Commented:
Great, Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.