一共设置了三个优先级,第一个正常优先级,第二个低优先级,第三个高优先级
运行效果:
代码:
1 void CTestProgressDlg::OnBnClickedBtnStart()
2 {
3 // TODO: 在此添加控件通知处理程序代码
4 // 创建线程
5 m_hThread1 = CreateThread(NULL, 0, Thread1, this, CREATE_SUSPENDED, NULL);
6 m_hThread2 = CreateThread(NULL, 0, Thread2, this, CREATE_SUSPENDED, NULL);
7 m_hThread3 = CreateThread(NULL, 0, Thread3, this, CREATE_SUSPENDED, NULL);
8 // 设置线程优先级
9 SetThreadPriority(m_hThread1, THREAD_PRIORITY_NORMAL);
10 SetThreadPriority(m_hThread2, THREAD_PRIORITY_LOWEST);
11 SetThreadPriority(m_hThread3, THREAD_PRIORITY_HIGHEST);
12 // 唤醒线程
13 ResumeThread(m_hThread1);
14 ResumeThread(m_hThread2);
15 ResumeThread(m_hThread3);
16 }
17 DWORD WINAPI CTestProgressDlg::Thread1(LPVOID lpParam)
18 {
19 CTestProgressDlg *pDlg = (CTestProgressDlg*)lpParam;
20 for(int i = 0;i < 10000;i++)
21 {
22 pDlg->m_progress1.SetPos(i);
23 }
24 return 0;
25 }
26 DWORD WINAPI CTestProgressDlg::Thread2(LPVOID lpParam)
27 {
28 CTestProgressDlg *pDlg = (CTestProgressDlg*)lpParam;
29 for(int i = 0;i < 10000;i++)
30 {
31 pDlg->m_progress2.SetPos(i);
32 }
33 return 0;
34 }
35 DWORD WINAPI CTestProgressDlg::Thread3(LPVOID lpParam)
36 {
37 CTestProgressDlg *pDlg = (CTestProgressDlg*)lpParam;
38 for(int i = 0;i < 10000;i++)
39 {
40 pDlg->m_progress3.SetPos(i);
41 }
42 return 0;
43 }
44
45 void CTestProgressDlg::OnBnClickedBtnPause()
46 {
47 // TODO: 在此添加控件通知处理程序代码
48 SuspendThread(m_hThread1);
49 SuspendThread(m_hThread2);
50 SuspendThread(m_hThread3);
51 }
52
53 void CTestProgressDlg::OnBnClickedBtnContinue()
54 {
55 // TODO: 在此添加控件通知处理程序代码
56 ResumeThread(m_hThread1);
57 ResumeThread(m_hThread2);
58 ResumeThread(m_hThread3);
59 }
时间: 2024-10-14 15:07:09