Click here to Skip to main content
15,885,109 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Friends,

I am new to VC++ environment. Here my job was to create a dialog from the thread and to be plotted on to the child dialog. Here I'm posting a pseudo code.

In file Sched.cpp
extern CPaint *m_dlg;
void CSched:: Minor()
{
   CWinThread *pThread = NULL;
   pThread = AfxBeginThread((AFX_THREADPROC)CallGraph,NULL);
   if(pThread == NULL)
      MessageBox("Thread Fails");
}

UINT CShed::CallGraph(LPVOID pParam) 
{
   m_dlg -> StartGraph();
   return TRUE;
}


In another file Paint.cpp
void CPaint::StartGraph()
{
   CPaint *m_dlg;
   m_dlg = new CPaint();
   m_dlg->Create(IDD_PAINT_DLG,NULL);
   m_dlg->ShowWindow(SW_SHOW);
}


Please reply as soon as possible. I am not getting what mistake is there in this code but I am sure that the program is compiling and thread is created and dialog is not created.

Thank you in advance
Posted
Updated 10-May-10 1:29am
v4
Comments
ThatsAlok 4-Jul-11 3:10am    
where are you giving memory to extern variable m_dlg

Excuse me for stating the bleeding obvious, but do you have a message loop somewhere in your program?
 
Share this answer
 
Comments
Albert Holguin 3-Jul-11 23:16pm    
OP said (in deleted solution):
Hello Michel..

I dint get what u r telling...Message looping means??..
ThatsAlok 4-Jul-11 3:12am    
when you create dialog box in MFC, it will provide you defualt messsage loop? so that not a question!
Please read the multithread GUI source code within WTL。
 
Share this answer
 
Agreed with albert, you can't have modeless dialog box within thread which is terminating after creation of dialog!
 
Share this answer
 
in addtion to my solution, you can keep it running by adding window message loop to your thread, some thing like this :-

C#
MSG lpmdg;
    while(GetMessage(&lpmdg,0,0,0))
    {
        DispatchMessage(&lpmdg);

    }


i forget, how to handle dialog close here, but let you know how to do that!
 
Share this answer
 
Check to see if there's any errors being returned from the Create() method when you try to create the dialog. There may also be an issue with creating a modeless dialog on a thread that just ends right after creating the dialog.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900