MFC or C # single button end While event loop

Source: Internet
Author: User

In a single-threaded application, we know that when a program enters a function A that takes a long time to process, the system will not respond to various actions of the user, including closing the application, and the program will go into suspended animation, that is, the interface stops responding to other actions.

About C # can call Application.doevents () directly in the while loop;

1 BOOL Isstart=false23while (!  Isstart)4{5     // event; 6     application.doevents (); 7 }89//Isstart can be changed to true on other buttons or the same button to end this loop

About C + + in the MFC interface, is also my current problems, can be resolved as follows:

1. As in C # above, convert application.doevents () into C + +: AfxGetApp ()->pumpmessage ();

2. Create a doevent function that also replaces the C # example:

1 //event handlers that are embedded in the loop so that other messages have a chance to be processed2 3 BOOL DoEvents ()4 {5 msg msg;6:: GetMessage (&msg,0,0,0);7     if(Msg.message = =wm_quit)8     {9 PostQuitMessage (msg.wparam);Ten          returnFALSE; One     } A     Else -     { -:: TranslateMessage (&msg); the::D ispatchmessage (&msg); -          returnTRUE; -     } -}

On the internet to look up a lot of information, basically is to create a doevent, today accidentally found the method 1

Share it to everyone. If you have any mistakes, you should correct them.

MFC or C # single button end While event loop

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.