Creating and Destroying a Window in CWinThread Derived Class
Hello,
(Using VC++ 6.0)
I am extremely frustrated with this and have burned many hours and still no
solution.
This should be simple.
I have created a sample app that does the following:
1) Creates a CWinThread derived class from Class Wizard called SeperateThread.
2) Creates a modeless dialog box on thread initialization
3) Destroys it on ExitInstance() SeperateThread.
Problem: ExitInstance() in cannot destroy the window I created just above
on thread InitInstance().
Code Snippets:
CTestThreaddingJunkDlg.h
CSeperateThread ThreadA; declared in the base .h file
In CTestThreaddingJunkDlg.cpp:
void CTestThreaddingJunkDlg::OnButton1()
{
ThreadA.CreateThread();
}
void CTestThreaddingJunkDlg::OnButton2()
{
ThreadA.ExitInstance();
}
In SeperateThread.h:
CDudeWindow * Duder;
In SeperateThread.cpp:
BOOL CSeperateThread::InitInstance()
{
Duder = new CDudeWindow ();
Duder->Create(CDudeWindow::IDD);
Duder->ShowWindow(SW_SHOW);
// works fine the first time around!!!!!
return TRUE;
}
int CSeperateThread::ExitInstance()
{
Duder->DestroyWindow(); // always crashes here and never closes window!
delete Duder;
return CWinThread::ExitInstance();
}
I am going to need to do another CreateThread() on ThreadA later (after it
is deleted or handle set to null), but if I can't uninitialize or exit and
destroy the window, there is no hope for recreating ThreadA later.
Any suggestions?
Thanks,
Rob