开发者

Hangs on CreateDialogIndirect in CWinThread derived class

开发者 https://www.devze.com 2023-01-17 11:26 出处:网络
I\'m new to multithreading. I created a class inherit from CWinThread called CMyUIThread, and also a dialog called CMyInfoDlg which has a text and a progress ctrl. I would to show modeless dialog in

I'm new to multithreading.

I created a class inherit from CWinThread called CMyUIThread, and also a dialog called CMyInfoDlg which has a text and a progress ctrl. I would to show modeless dialog in new created thread. Below is partial code:

BOOL CMyUIThread::InitInstance()
{
// TODO: perform and per-thread initialization here
// NOTE: the memory allocated below is freed by CMyInfoDlg::OnDestroy (it deletes itself)
m_pDlg = new CMyInfoDlg(CWnd::FromHandle(m_hwndParent));
VERIFY( m_pDlg->Create(IDD_THREADUI_DIALOG, CWnd::FromHandle(m_hwndParent)) );
g_hwndProgress = m_pDlg->GetSafeHwnd();
::ShowWindow(g_hwndProgress, SW_SHOW); // show window for the first time
开发者_开发问答return TRUE;
}

In my main frame, I did the following

m_pThread = new CGSUIThread(m_hwndParent);
m_pThread->m_bAutoDelete = FALSE;
VERIFY( m_pThread->CreateThread() );

OK. In this case, it works fine.

However, when I merge it into another big module which has main frame, problem came: it hangs on:

VERIFY( m_pDlg->Create(IDD_THREADUI_DIALOG, CWnd::FromHandle(m_hwndParent)) );

When I tracked down, it is acutally hangs on CreateIndirectDialog.

BOOL CDialog::Create(LPCTSTR lpszTemplateName, CWnd* pParentWnd)

I dont' know why it's like that.

Anyone knows why?


Best advice: check the call stack. You can get the public Windows symbols from MS servers, and see what's hanging specifically. Best guess is maybe a messaging deadlock, or perhaps something to do with the CWnd*. Gotta look at the call stack, though, and see what's really pending.

0

精彩评论

暂无评论...
验证码 换一张
取 消