⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 threadfunction.cpp

📁 一个用来对非常大的数进行科学计算的程序库
💻 CPP
字号:
#include "stdafx.h"
#include "resource.h"
#include "TestAllDlg.h"
#include "MyUsefulFunction.h"

UINT RandomTestThread(LPVOID param)
{
	HANDLE hEvent = OpenEvent(EVENT_MODIFY_STATE, FALSE, "ShouldStop");
	ASSERT(hEvent);
	
	RANDOMTESTPARAM * rtp = (RANDOMTESTPARAM *) param;
	UINT nType = rtp -> nType;
	UINT nLoop = rtp -> nLoop;
	rtp -> dwElapsedTime = 0;

	UINT i;
	
	switch(nType)
	{
	case 0:
		for (i = 1; i <= int(nLoop); i++)
		{
			if (!WaitForSingleObject(hEvent, 0))
			{
				SendMessage(rtp -> hWndChild, WM_RESETREADONLYFLAG, 0, 0);

				CString cs;
				cs.Format("计算量:%u, 用时:%lu 毫秒", i - 1, rtp -> dwElapsedTime);
				MessageBox(rtp -> hWndTop, cs, "统计", MB_OK | MB_ICONINFORMATION);

				return 1;   // Break
			}
			
			SendMessage(rtp -> hWndChild, WM_RANDOMTEST, 0, UINT(rtp));
			SendMessage(rtp -> hWndTop, WM_ADDPROGRESS, 0, 0);
		}
		SendMessage(rtp -> hWndChild, WM_RESETREADONLYFLAG, 0, 0);
		break;

	case 1:
		for (i = 1; i <= int(nLoop); i++)
		{
			if (!WaitForSingleObject(hEvent, 0))
			{
				SendMessage(rtp -> hWndChild, WM_RESETREADONLYFLAG, 0, 0);

				CString cs;
				cs.Format("计算量:%u, 用时:%lu 毫秒", i - 1, rtp -> dwElapsedTime);
				MessageBox(rtp -> hWndTop, cs, "统计", MB_OK | MB_ICONINFORMATION);

				return 1;   // Break
			}

			SendMessage(rtp -> hWndChild, WM_RANDOMTEST, 0, UINT(rtp));
			SendMessage(rtp -> hWndTop, WM_ADDPROGRESS, 0, 0);
 		}
		SendMessage(rtp -> hWndChild, WM_RESETREADONLYFLAG, 0, 0);
		break;
	}
	
	SendMessage(rtp -> hWndTop, WM_RESETREADONLYFLAG, 0, 0);

	CString cs;
	cs.Format("计算量:%u, 用时:%lu 毫秒", nLoop, rtp -> dwElapsedTime);
	MessageBox(rtp -> hWndTop, cs, "统计", MB_OK | MB_ICONINFORMATION);

	return (UINT) rtp;  // Finish
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -