我有一个属性表,我有四页。在第二页我有一个列表控件和一个按钮。并在第二页我创建了两个线程。当我点击下一个在第一页,我试图使用从网络中检索的一些值枚举列表控件。因此,在这里,搜索对话框和枚举列表正在两个并行运行的不同线程中处理。在页面的前面,搜索对话框弹出并且后台从网络的价值检索和列表得到枚举这些值。在那个时候,如果我点击客户区,那么这个搜索对话框正在最小化。但这应该不会发生,除非搜索对话框被解雇,我不能给予对父窗口的访问(与ModalDiaolg框相同的场景,正如我们所知道的,除非子窗口关闭,否则我们将无法访问父权,同样的场景是必需的)f或我)。这是我为了让这些线程一次运行而完成的代码。如何使用多线程锁定资源?
BOOL CModelSelectionView::CreateModelThread()
{
unsigned threadID;
if(NULL == (m_hModelThread = (HANDLE)_beginthreadex(
NULL,
0,
&CModelSelectionView::ModelThreadProc,
reinterpret_cast<void*>(this),
0,
&threadID)))
{
return FALSE;
}
return TRUE;
}
//这个线程是搜索对话框
UINT CModelSelectionView::ModelThreadProc(void* lpContext)
{
CModelSelectionView *pSelectModelFromList =
reinterpret_cast<CModelSelectionView*> (lpContext);`
AfxSetResourceHandle(theApp.m_hDialogResource);
CSearchingView SearchView(IDD_DIALOG_SEARCH);
INT nRes = SearchView.DoModal();
::CloseHandle(pSelectModelFromList->m_hModelThread);
pSelectModelFromList->m_hModelThread = NULL;
_endthreadex(0);
return TRUE;
}
BOOL CModelSelectionView::CreateInstallerThread()
{
unsigned threadID;
if(NULL == (m_hInstallerThread = (HANDLE)_beginthreadex(
NULL,
0,
&CModelSelectionView::InstallerThreadProc,
reinterpret_cast<void*>(this),
0,
&threadID)))
{
return FALSE;
}
return TRUE;
}
用于初始化一些值
UINT CModelSelectionView::InstallerThreadProc(void* lpContext)
{
CModelSelectionView *pSelectModelFromList =
reinterpret_cast<CModelSelectionView*> (lpContext);
pSelectModelFromList->m_listCtrl.DeleteAllItems();
LVITEM lvitem;
lvitem.mask = LVIF_TEXT;
lvitem.iItem = 0;
lvitem.iSubItem = 0;
lvitem.pszText = L"";
lvitem.cchTextMax = sizeof(lvitem.pszText);
int nItem = pSelectModelFromList->m_listCtrl.InsertItem(&lvitem);
::Sleep(200);
pSelectModelFromList->m_listCtrl.SetItemText(0,1,L"XXX");
pSelectModelFromList->m_listCtrl.SetItemText(0,2,L"YYY");
pSelectModelFromList->m_listCtrl.SetItemText(0,3,L"ZZZ");
pSelectModelFromList->m_listCtrl.SetItemText(0,4,L"AAAA");
::Sleep(200);
::TerminateThread(pSelectModelFromList->m_hModelThread, 0);
::CloseHandle(pSelectModelFromList->m_hModelThread);
pSelectModelFromList->m_hModelThread = NULL;
::CloseHandle(pSelectModelFromList->m_hInstallerThread);
pSelectModelFromList->m_hInstallerThread = NULL;
_endthreadex(0);
return TRUE;
}
清单//第二个线程,直到除非搜索对话框关闭它不应该被允许访问父窗口。例如,当点击一个按钮,并为那个按钮处理程序,我打电话domodal然后弹出一个子对话框,直到除非我们忽略那个对话框我们w生病不允许访问父母的权利,同样我必须得到在这种情况下。
任何人都可以建议我怎么做到这一点。
任何人都可以请建议我如何