
文章插圖
【vc多線程 vc多線程 verify宏】大家好,小豆豆來為大家解答以上的問題 。vc多線程 verify宏,vc多線程這個很多人還不知道,現在讓我們一起來看看吧!
1、你的意思說程序可以同時做2件事,不會因為一件而暫停吧.下面的代碼就是你說的//: Defines the entry point for the application.//#include "stdafx.h"#include "MultipleThread.h"#include INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);int APIENTRY _tWinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPTSTRlpCmdLine,intnCmdShow){ DialogBox(NULL, MAKEINTRESOURCE(IDD_ABOUTBOX), NULL, About); return (int) 0;}const int MAX_PROCESS_PRIORITY_NUM = 5;const int MAX_THREAD_PRIORITY_NUM = 6;TCHAR* pszProcPriorityName[MAX_PROCESS_PRIORITY_NUM] = {L"High", L"Above Normal", L"Normal", L"Below Normal", L"Idle"};TCHAR* pszThreadPriorityName[MAX_THREAD_PRIORITY_NUM] = {L"High", L"Above Normal", L"Normal", L"Below Normal", L"Lowst", L"Idle"};int nProcessPriority[MAX_PROCESS_PRIORITY_NUM] = {HIGH_PRIORITY_CLASS, ABOVE_NORMAL_PRIORITY_CLASS, NORMAL_PRIORITY_CLASS,BELOW_NORMAL_PRIORITY_CLASS, IDLE_PRIORITY_CLASS };int nThreadPriority[MAX_THREAD_PRIORITY_NUM] = {THREAD_PRIORITY_HIGHEST, THREAD_PRIORITY_ABOVE_NORMAL, THREAD_PRIORITY_NORMAL, THREAD_PRIORITY_BELOW_NORMAL,THREAD_PRIORITY_LOWEST, THREAD_PRIORITY_IDLE};HWND hDlg = NULL;DWORD WINAPI MyThread(PVOID pvParam) //計數線程函數{ DWORDnCount = 0; while(nCount ++ < MAXLONG) {SetDlgItemInt(hDlg, IDC_EDIT2, nCount, false); } return 0;}HANDLE hThread = NULL;INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam){ UNREFERENCED_PARAMETER(lParam); switch (message) { case WM_INITDIALOG:for(int i = 0; i < MAX_PROCESS_PRIORITY_NUM; i++)SendDlgItemMessage(hDlg, IDC_COMBO2, CB_ADDSTRING, 0, (LPARAM)pszProcPriorityName[i]);SendDlgItemMessage(hDlg, IDC_COMBO2, CB_SETCURSEL, 2, 0);for(int i = 0; i < MAX_THREAD_PRIORITY_NUM; i++)SendDlgItemMessage(hDlg, IDC_COMBO3, CB_ADDSTRING, 0, (LPARAM)pszThreadPriorityName[i]);SendDlgItemMessage(hDlg, IDC_COMBO3, CB_SETCURSEL, 2, 0);hThread = CreateThread(NULL, 0, MyThread, (PVOID)&hDlg, CREATE_SUSPENDED,NULL); //創建一個新的進程EnableWindow(GetDlgItem(hDlg, IDC_BUTTON3), false);::hDlg = hDlg;SetProcessPriorityBoost(GetCurrentProcess(), false);SetThreadPriorityBoost(hThread, false);return (INT_PTR)TRUE; case WM_COMMAND:if (HIWORD(wParam) == CBN_SELCHANGE){if(LOWORD(wParam) == IDC_COMBO2){int nIndex = SendDlgItemMessage(hDlg, IDC_COMBO2, CB_GETCURSEL, 0, 0);SetPriorityClass(GetCurrentProcess(), nProcessPriority[nIndex]);}else if(LOWORD(wParam) == IDC_COMBO3){int nIndex = SendDlgItemMessage(hDlg, IDC_COMBO3, CB_GETCURSEL, 0, 0);SetThreadPriority(hThread, nThreadPriority[nIndex]);}return (INT_PTR)TRUE;}else if(LOWORD(wParam) == IDC_BUTTON2){EnableWindow(GetDlgItem(hDlg, IDC_BUTTON3), true);EnableWindow(GetDlgItem(hDlg, IDC_BUTTON2), false);ResumeThread(hThread);MessageBox(hDlg, L"Resume", L"提示", MB_OK);}else if(LOWORD(wParam) == IDC_BUTTON3){EnableWindow(GetDlgItem(hDlg, IDC_BUTTON2), true);EnableWindow(GetDlgItem(hDlg, IDC_BUTTON3), false);SuspendThread(hThread);MessageBox(hDlg, L"Suspend", L"提示", MB_OK);}break; case WM_CLOSE:CloseHandle(hThread);ExitProcess(0);break; } return (INT_PTR)FALSE;}在SetTimer 換成 CreateThread 。
本文到此分享完畢,希望對大家有所幫助 。
- 20毫升乙醇等于多少克
- 血液循環全身要多長時間才能恢復
- 審車可以提前多久去審車
- 云南有多少個市 云南有多少個市和縣
- 士官工資是多少 士官工資表明細
- 冰棍的熱量 冰棍的熱量有多高
- 奧迪a4l避震器多久換一個
- 白花小松多肉怎么繁殖
- 軒逸多功能按鍵安裝教程
- a類駕駛證的年齡限制是多少
