Advertisement

06.25.2008 at 08:30AM PDT, ID: 23514897
[x]
Attachment Details

CWinThread and CDialog - getting them work together

Asked by Sonja_M in Windows MFC Programming, Microsoft Visual C++.Net, Microsoft Visual C++

Tags: Microsoft, Visual Studio, 6

Hello,

I have created a new thread - that works perfect. Now I want to display a CDialog in this thread. In a Thread Montor a new thread with the name of the dialog is shown but i can not see the dialog. I have called the dialog without a thread - that worked. That have I done wrong?

Below some code which may help.

Greedings SonjaStart Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
// Call of the thread
//--------------------
 
  CMyThread * MyThread = new CMyThread();
  MyThread ->CreateThread(CREATE_SUSPENDED);
  MyThread ->m_Parameter = Parameter;
  MyThread ->m_pDialog = pDialog;
  MyThread ->ResumeThread();
 
// MyThread.cpp - class CMyThread : public CWinThread
//--------------
 
int MyThread::Run()
{
  //pDialog initialized to NULL in the constructor of CMyWnd class
   CMyDialog* pDialog = new CMyDialog();
   //Check if new succeeded and we got a valid pointer to a dialog object
   if(pDialog != NULL)
   {
      BOOL ret = pDialog->Create(IDD_MYDIALOG,NULL); // <- In the debugger it stops here
      if(!ret)   //Create failed.
         AfxMessageBox("Error creating Dialog");
      pDialog->ShowWindow(SW_SHOW);
   }
   else
      AfxMessageBox("Error Creating Dialog Object");
  return 0;
}
 
 
[+][-]06.25.2008 at 08:39AM PDT, ID: 21866855

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.25.2008 at 08:52AM PDT, ID: 21867022

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.26.2008 at 05:25AM PDT, ID: 21873986

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.26.2008 at 06:27AM PDT, ID: 21874527

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.26.2008 at 06:55AM PDT, ID: 21874798

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Windows MFC Programming, Microsoft Visual C++.Net, Microsoft Visual C++
Tags: Microsoft, Visual Studio, 6
Sign Up Now!
Solution Provided By: mrwad99
Participating Experts: 3
Solution Grade: A
 
 
[+][-]06.26.2008 at 09:53AM PDT, ID: 21876669

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628