给位高手,我刚用MFC基于对话框弄个多个进度条同时运行,但不知如何同时启动他们和同时让他们暂停,请高手指点,我知道是要创建线程和挂起,具体不会编创建和启动
解决方案 »
- VC如何实现在右下角浮出小框框
- 求救 相关winpcap捕获数据包后如何分析包,提取敏感信息。。。跪求!!!
- 如何在不同进程之间用sendmessage传递对象?
- 一个菜鸟的问题!
- 关于大型数据库设计的问题,高手请进!
- XP下VS2005开发的MFC程序,到了win7下就无法运行?
- 请问怎样才能学好一些网络协议??
- vc中如何读取文本文件,一航一航的读取,(来者有分)
- Activex一刷新窗口就成灰色了
- 问一个简单问题,SQL Server中如何截短tempdb数据库。
- MFC多文档程序初始化时CMDIFrameWnd和CMDIChildWnd是如何被联系在一起的?
- 用MFC写的单机游戏,中间件是MFC吗?
http://download.csdn.net/source/2516354
SuspendThread(hThread);
我想用一个开始按钮运行线程,用暂停将线程挂起,有代码可以参考么
{
// TODO: Add your control notification handler code here
m_Prog1.SetRange(1,20000); //设置滑块的滑动范围
m_Prog2.SetRange(1,20000); //设置滑块的滑动范围
m_Prog3.SetRange(1,20000); //设置滑块的滑动范围
HANDLE hThread1 = CreateThread(NULL,0,ThreadProc1,this,CREATE_SUSPENDED,NULL); //创建线程,并挂起CREATE_SUSPENDED
SetThreadPriority(hThread1,THREAD_PRIORITY_LOWEST); //设置优先级 HANDLE hThread2 = CreateThread(NULL,0,ThreadProc2,this,CREATE_SUSPENDED,NULL); //创建线程,并挂起CREATE_SUSPENDED
SetThreadPriority(hThread2,THREAD_PRIORITY_BELOW_NORMAL); //设置优先级 HANDLE hThread3 = CreateThread(NULL,0,ThreadProc3,this,CREATE_SUSPENDED,NULL); //创建线程,并挂起CREATE_SUSPENDED
SetThreadPriority(hThread3,THREAD_PRIORITY_HIGHEST); //设置优先级
ResumeThread(hThread1); //恢复线程1
ResumeThread(hThread2); //恢复线程2
ResumeThread(hThread3); //恢复线程3
}void CEreDlg::OnButton2()
{
// TODO: Add your control notification handler code here
SuspendThread( hThread1); //挂起线程1
SuspendThread( hThread2); //挂起线程2
SuspendThread( hThread3); //挂起线程3
}
F:\学习\新建文件夹 (2)\ere\ereDlg.cpp(229) : error C2065: 'hThread1' : undeclared identifier
F:\学习\新建文件夹 (2)\ere\ereDlg.cpp(230) : error C2065: 'hThread2' : undeclared identifier
F:\学习\新建文件夹 (2)\ere\ereDlg.cpp(231) : error C2065: 'hThread3' : undeclared identifier
执行 cl.exe 时出错.
{...xxx
关于线程的案例请发我 谢谢!!! [email protected]
{
public:
CAboutDlg();// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA // ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
HANDLE hThread1;
HANDLE hThread2;
HANDLE hThread3;CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CEreDlg dialogCEreDlg::CEreDlg(CWnd* pParent /*=NULL*/)
: CDialog(CEreDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CEreDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}void CEreDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CEreDlg)
DDX_Control(pDX, IDC_PROGRESS3, m_Prog3);
DDX_Control(pDX, IDC_PROGRESS2, m_Prog2);
DDX_Control(pDX, IDC_PROGRESS1, m_Prog1);
//}}AFX_DATA_MAP
}BEGIN_MESSAGE_MAP(CEreDlg, CDialog)
//{{AFX_MSG_MAP(CEreDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CEreDlg message handlersBOOL CEreDlg::OnInitDialog()
{
CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
} // Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}void CEreDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.void CEreDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CEreDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
DWORD __stdcall ThreadProc1(LPVOID lpParameter)
{
CEreDlg* pDlg = (CEreDlg*)lpParameter;
for (int i=0; i<=20000; i++)
{
pDlg->m_Prog1.SetPos(i);
Sleep(2);
}
return 0;
}
DWORD __stdcall ThreadProc2(LPVOID lpParameter)
{
CEreDlg* pDlg = (CEreDlg*)lpParameter;
for (int i=0; i<=20000; i++)
{
pDlg->m_Prog2.SetPos(i);
Sleep(2);
}
return 0;
}
DWORD __stdcall ThreadProc3(LPVOID lpParameter)
{
CEreDlg* pDlg = (CEreDlg*)lpParameter;
for (int i=0; i<=20000; i++)
{
pDlg->m_Prog3.SetPos(i);
Sleep(2);
}
return 0;
}
void CEreDlg::OnButton1()
{
// TODO: Add your control notification handler code here
m_Prog1.SetRange(1,20000); //设置滑块的滑动范围
m_Prog2.SetRange(1,20000); //设置滑块的滑动范围
m_Prog3.SetRange(1,20000); //设置滑块的滑动范围
HANDLE hThread1 = CreateThread(NULL,0,ThreadProc1,this,CREATE_SUSPENDED,NULL); //创建线程,并挂起CREATE_SUSPENDED
SetThreadPriority(hThread1,THREAD_PRIORITY_LOWEST); //设置优先级 HANDLE hThread2 = CreateThread(NULL,0,ThreadProc2,this,CREATE_SUSPENDED,NULL); //创建线程,并挂起CREATE_SUSPENDED
SetThreadPriority(hThread2,THREAD_PRIORITY_BELOW_NORMAL); //设置优先级 HANDLE hThread3 = CreateThread(NULL,0,ThreadProc3,this,CREATE_SUSPENDED,NULL); //创建线程,并挂起CREATE_SUSPENDED
SetThreadPriority(hThread3,THREAD_PRIORITY_HIGHEST); //设置优先级
ResumeThread(hThread1); //恢复线程
ResumeThread(hThread2); //恢复线程
ResumeThread(hThread3); //恢复线程
}void CEreDlg::OnButton2()
{
// TODO: Add your control notification handler code here
SuspendThread( hThread1); //挂起线程
SuspendThread( hThread2); //挂起线程
SuspendThread( hThread3); //挂起线程