A problem I saw on the Internet makes sense:
Q: Windows uses the message polling mechanism.ProgramIt will receive messages continuously until the end of the cycle, isn't it very resource-consuming? If I write a C ++ program and use a loop to constantly update the display time, the CPU usage will be very high, then what method does Windows use to make those message polling programs occupy very little resources?
A:In a message loop, the most commonly used functions are getmessage () and peekmessage (). When the message queue is empty, the getmessage () function does not return a time slice, the thread does not occupy CPU resources. The peekmessage function returns immediately even if the message queue is empty, rather than blocking. The message loop does not occupy a lot of CPU resources because getmessage does not return when the message queue is empty. At this time, the operating system switches away from the thread until the thread receives the message.