vc多线程 vc多线程 verify宏


vc多线程 vc多线程 verify宏

文章插图
【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 。
本文到此分享完毕,希望对大家有所帮助 。