/*
* Worker.cpp
*
* Sample code for "Multithreading Applications in Win32"
* This is from Chapter 14, Listing 14-3
*
* Demonstrate using worker threads that have
* their own message queue but no window.
*/
#define WIN32_LEAN_AND_MEAN
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <process.h>
#include <string.h>
#include "MtVerify.h"
unsigned WINAPI ThreadFunc(void* p);
HANDLE ghEvent;
#define WM_JOB_PRINT_AS_IS WM_APP + 0x0001
#define WM_JOB_PRINT_REVERSE WM_APP + 0x0002
#define WM_JOB_PRINT_LOWER WM_APP + 0x0003
#define WM_LEIWEI WM_APP + 0x0004
int main(VOID)
{
HANDLE hThread;
unsigned tid;
// Give the new thread something to talk
// to us with.
//创建手动事件
ghEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
unsigned CurrentId = GetCurrentThreadId();
UNREFERENCED_PARAMETER(CurrentId);
hThread &
Worker线程使用消息循环
最新推荐文章于 2022-08-16 10:26:11 发布
这个示例代码展示了如何在Win32环境中创建一个带有自己消息队列但没有窗口的worker线程。主线程通过PostThreadMessage发送WM_JOB_开头的消息,worker线程根据消息类型进行不同操作,如正向打印、反向打印和转换为小写等。
摘要由CSDN通过智能技术生成