Msgsleep, which can process messages.

Source: Internet
Author: User
//// This code can be used for free, but you are solely responsible for any consequences caused by improper use. // inline bool msgsleep (DWORD dwmilliseconds, uint wremovemsg = pm_remove, uint wexitmsg = wm_quit); bool msgsleep (DWORD dwmilliseconds, uint timeout, uint wexitmsg)
{
_ Assert (wexitmsg = wm_quit | (wexitmsg> wm_user & wexitmsg <wm_app); DWORD dwstart =: gettickcount ();
MSG;: Sleep (0); // The sleep is to be achieved. Therefore, call sleep (0) at the beginning to release the control while (: gettickcount () -dwstart <dwmilliseconds) // if the time is enough, you do not need peekmessage and exit directly, for example, dwmilliseconds = 0;
{
// By default, pm_remove is used to process all types of messages. However, you can set wremovemsg to filter the messages you want.
If (: peekmessage (& MSG, null, 0, 0, wremovemsg ))
{
If (msg. Message = wm_quit | MSG. Message = wexitmsg) // If a specified message is received, sleep is no longer performed. The default value is wm_quit.
{
If (msg. Message = wm_quit)
: Postquitmessage (INT) msg. wparam); // if it is wm_quit, you must resend it. Return false; // If the wait time is not reached, false is returned.
} If (wremovemsg! = Pm_noremove) // If pm_noremove is specified, the message is not processed, and the sleep function is the same.
{
: Translatemessage (& MSG );
: Dispatchmessage (& MSG );
}
}: Sleep (0); // create a sleep (0). Wait for a while.
} Return true; // If the wait time is confirmed, false is returned.
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.