Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VC6 MFC UI threads
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 9-May-10 18:39pm
Edited 10-May-10 2:29am
Moak11.4K
v4
Comments
ThatsAlok at 4-Jul-11 3:10am
   
where are you giving memory to extern variable m_dlg
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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

I dint get what u r telling...Message looping means??..
ThatsAlok at 4-Jul-11 3:12am
   
when you create dialog box in MFC, it will provide you defualt messsage loop? so that not a question!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Please read the multithread GUI source code within WTL。
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

Agreed with albert, you can't have modeless dialog box within thread which is terminating after creation of dialog!
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

in addtion to my solution, you can keep it running by adding window message loop to your thread, some thing like this :-
 
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!
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 350
1 Jochen Arndt 150
2 PIEBALDconsult 110
3 Richard MacCutchan 105
4 Sergey Alexandrovich Kryukov 104
0 OriginalGriff 6,055
1 DamithSL 4,621
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,500
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 4 Jul 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100