码迷,mamicode.com
首页 > 其他好文 > 详细

可等待计时器添加APC测试

时间:2017-04-01 10:34:33      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:api   hand   com   app   pts   word   timer   init   hello   

unsigned APIENTRY ThreadProc(void *p)
{
	WaitForSingleObject(g_hWaitableTimer, INFINITE);

	MessageBox(NULL, _T("线程开始启动"), _T("HELLO"), MB_OK);

	return 0;
}

void APIENTRY ApcCompletionRoutine(PVOID pParm, DWORD dwTimerLowValue, DWORD dwTimeHighValue)
{
	MessageBox(NULL, _T("ApcCompletionRoutine开始启动"), _T("HELLO"), MB_OK);

	return;
}

int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
	UNREFERENCED_PARAMETER(hPrevInstance);
	UNREFERENCED_PARAMETER(lpCmdLine);

 	// TODO: 在此放置代码。
	unsigned ThreadId;
	HANDLE hThread = (HANDLE)_beginthreadex(NULL, 0, ThreadProc, NULL, NULL, &ThreadId);

        g_hWaitableTimer = CreateWaitableTimer(NULL, FALSE, NULL);
	LARGE_INTEGER liStartTime;
	liStartTime.QuadPart = -(5 * 1000 * 1000 * 10);
	SetWaitableTimer(g_hWaitableTimer, &liStartTime, 0, ApcCompletionRoutine, NULL, FALSE);
	SleepEx(INFINITE, TRUE);     // 关键

	CloseHandle(hThread);
	CloseHandle(g_hWaitableTimer);

	MSG msg;
	HACCEL hAccelTable;

	// 初始化全局字符串
	LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
	LoadString(hInstance, IDC_WAITABLETIMERTEST, szWindowClass, MAX_LOADSTRING);
	MyRegisterClass(hInstance);

	// 执行应用程序初始化:
	if (!InitInstance (hInstance, nCmdShow))
	{
		return FALSE;
	}

	hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_WAITABLETIMERTEST));

	// 主消息循环:
	while (GetMessage(&msg, NULL, 0, 0))
	{
		if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}

	return (int) msg.wParam;
}

  

可等待计时器添加APC测试

标签:api   hand   com   app   pts   word   timer   init   hello   

原文地址:http://www.cnblogs.com/xiaobingqianrui/p/6654840.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!