MFC线程访问控件变量
MFC线程访问控件变量附代码:CWinThread*MyThread;voidCTestThreadDlg::OnBnClickedButton1(){//HWNDhWn...
MFC线程访问控件变量
附代码:
CWinThread* MyThread;
void CTestThreadDlg::OnBnClickedButton1()
{
//HWND hWnd = GetSafeHwnd(); //获得一个窗口的窗口句柄
for ( int i=0;i<10;i++)
{
MyThread=AfxBeginThread(SubProcess,(LPVOID)this,THREAD_PRIORITY_NORMAL,0,0,NULL);
int nIndex;
CString strIndex;
nIndex=m_ListCtrl.GetItemCount();
strIndex.Format(L"%d", a);
m_ListCtrl.InsertItem(nIndex,NULL);
m_ListCtrl.SetItemText(nIndex,1,strIndex);
}
}
#include "stdafx.h"
class StartThread
{
public:
UINT SubProcess(LPVOID param);
protected:
private:
};
UINT SubProcess(LPVOID param);
#include "stdafx.h"
#include "ThreadClass.h"
UINT SubProcess(LPVOID pParam)
{
//CTestThreadDlg *pDlg=(CTestThreadDlg *)pParam;
a=0;
while(true)
{
int nIndex;
CString strIndex;
nIndex=pDlg->m_ListCtrl.GetItemCount();
strIndex.Format(L"%d", a);
pDlg->m_ListCtrl.InsertItem(nIndex,NULL);
pDlg->m_ListCtrl.SetItemText(nIndex,1,strIndex);
a++;
}
return 0;
} 展开
附代码:
CWinThread* MyThread;
void CTestThreadDlg::OnBnClickedButton1()
{
//HWND hWnd = GetSafeHwnd(); //获得一个窗口的窗口句柄
for ( int i=0;i<10;i++)
{
MyThread=AfxBeginThread(SubProcess,(LPVOID)this,THREAD_PRIORITY_NORMAL,0,0,NULL);
int nIndex;
CString strIndex;
nIndex=m_ListCtrl.GetItemCount();
strIndex.Format(L"%d", a);
m_ListCtrl.InsertItem(nIndex,NULL);
m_ListCtrl.SetItemText(nIndex,1,strIndex);
}
}
#include "stdafx.h"
class StartThread
{
public:
UINT SubProcess(LPVOID param);
protected:
private:
};
UINT SubProcess(LPVOID param);
#include "stdafx.h"
#include "ThreadClass.h"
UINT SubProcess(LPVOID pParam)
{
//CTestThreadDlg *pDlg=(CTestThreadDlg *)pParam;
a=0;
while(true)
{
int nIndex;
CString strIndex;
nIndex=pDlg->m_ListCtrl.GetItemCount();
strIndex.Format(L"%d", a);
pDlg->m_ListCtrl.InsertItem(nIndex,NULL);
pDlg->m_ListCtrl.SetItemText(nIndex,1,strIndex);
a++;
}
return 0;
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询