A process in Windows can contain multiple threads, consisting of multiple threads. in the Windows in an application, a form is called by a UI Threads ( User Interface Thread ) "is created by a special type of thread. A UI thread contains a message loop to a column. While the window is running, pressing the control or doing something to the window is equivalent to inserting the message into the message loop queue, and then the response function of the corresponding message is called by the system, causing the user operation to be responded to.
According to this work process, when the response function of a window message takes a lot of time, it must affect the window's response to the next message. Therefore, using multithreading should be a good choice for responding to more time-consuming operations. That is, a thread is created in the response function of the control, and the time-consuming operation is completed in the thread function.
WaitForSingleObject () is used to wait for a response to a thread function, which can also block the operation of the message loop queue and affect the window's response speed.
Note: Create thread functions: CreateThread (NULL, 0, ThreadProc, (LPVOID) NULL, 0, NULL);
Format of the thread function: DWORD WINAPI threadproc(LPVOID lpparameter);
among them, a thread function must be a global function or a static member function
Relationship between Windows window message loops and multithreading