Hi,
I am currently writing an application, which have to create on run-time a
new Control ( for example a CEdit-Control ) in a sperate thread. But when
the thread tries to create the new Control with a call to Create the
application hangs. The class which holds the Thread looks like the following
( The code is only for demonstration purpose ):
class Testing
{
public:
Testing() : bCreate(true)
{
}
void set_parent(CWnd* pWnd)
{
m_pWnd = pWnd;
}
void start_thread()
{
m_hThread = ::CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)
processing,
(LPVOID) this, 0, NULL);
}
void finish()
{
::CloseHandle(m_hThread);
}
static int processing(LPVOID pParam)
{
// try to get the processor-object to have access to the
Communication-Interface
// and all the other Processor-Specific-Things
Testing* pProcessor = static_cast<Testing* >(pParam);
while(true)
{
if(pProcessor->bCreate)
{
pProcessor->edit.Create(0, CRect(50, 50, 180, 180),
pProcessor->m_pWnd, 0);
pProcessor->bCreate = false;
}
}
return 0;
}
protected:
CWnd* m_pWnd;
HANDLE m_hThread;
bool bCreate;
CEdit edit;
};
In the InitInstance of my Dialog-based-MFC-Application I call then:
_testing.set_parent(this);
_testing.start_thread();
Whereby _testing is an object of Testing and a class member of the
Dialog-Class.
Maybe it looks strange, that for the creation of the thread I use an
SDK-function and not the MFC to create a thread, but the problem is, that in
my project the Thread-Creation is done by another vendor by the SDK and I
dont wanna change it, only if there is no other possibility?
How can I solve this problem?
Thanks in advance
Sebastian